如何在iPhone应用程序的Documents文件夹中重命名文件夹?

时间:2011-02-22 11:34:12

标签: iphone objective-c cocoa-touch ios-4.2

如何在iPhone应用程序的Documents文件夹中重命名文件夹?

这是一个由我的应用程序创建的文件夹,根据用户的选择,它应该重命名。

我们怎么能这样做?

2 个答案:

答案 0 :(得分:5)

答案 1 :(得分: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]);
}