如何在iPhone应用程序的Documents文件夹中重命名文件夹?
这是一个由我的应用程序创建的文件夹,根据用户的选择,它应该重命名。
我们怎么能这样做?
答案 0 :(得分:5)
请参阅此链接以重命名Documents目录中的文件:
修改强> 查看此链接以重命名目录:
https://www.stackoverflow.com/questions/4486979/how-to-rename-directories
答案 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]);
}