0

How can I rename a folder in my iPhone app's Documents folder?

It is a folder created by from my app and based on user's choice it should be renamed.

How can we do so?

Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216

2 Answers2

5

See this link for renaming files in Documents directory:

http://iosdevelopertips.com/data-file-management/iphone-file-system-creating-renaming-and-deleting-files.html

EDIT: Check out this link for renaming directories:

https://www.stackoverflow.com/questions/4486979/how-to-rename-directories

Cœur
  • 37,241
  • 25
  • 195
  • 267
ipraba
  • 16,485
  • 4
  • 59
  • 58
  • What I got from this link is that this link is for renaming files in Documents directory but I want to rename a folder in Documents directory and not a file. What can be done? – Parth Bhatt Feb 22 '11 at 12:08
  • Sorry man..My mistake.. See this link http://stackoverflow.com/questions/4486979/how-to-rename-directories – ipraba Feb 22 '11 at 12:57
  • Thanks !! BuildSucceeded I got the answer from stackoverflow link which you provided. Thanks a lot. :] Also I have edited your answer and added the stackoverflow link in the answer itself. – Parth Bhatt Feb 23 '11 at 04:26
0
// Rename the file, by moving the file
//Ex rename file1 to file2 use this code


NSError *error = nil;
    NSFileManager *filemgr = [[NSFileManager alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"file1.txt"];

NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"file2.txt"];

// Attempt the move
if ([filemgr moveItemAtPath:filePath toPath:filePath2 error:&error] != YES){
    NSLog(@"Unable to move file: %@", [error localizedDescription]);
}
Tibidabo
  • 21,461
  • 5
  • 90
  • 86
Almand
  • 333
  • 2
  • 4
  • 9