开发者

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

开发者 https://www.devze.com 2023-02-12 20:11 出处:网络
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开发者_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]);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消