这可能很容易,但我没有遇到问题。
我正在使用下面的代码重命名文档目录的文件夹,并且除了一种情况外工作正常。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Photos"];
NSArray * arrAllItems = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL]; // List of all items
NSString *filePath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", [arrAllItems objectAtIndex:tagSelected]]];
NSString *newDirectoryName = txtAlbumName.text; // Name entered by user
NSString *oldPath = filePath;
NSString *newPath = [[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newDirectoryName];
NSError *error = nil;
[[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:newPath error:&error];
if (error) {
NSLog(@"%@",error.localizedDescription);
// handle error
}
现在,我的问题是如果there is a folder named "A"(capital letter A) and I am renaming it to "a" (small letter a), then it is not working and giving an error.
我没有找到问题所在。