How can I rename a folder in my iPhone app's Documents folder?
How can开发者_Go百科 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?
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
// 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]);
}
精彩评论