Rename the folder of document directory
This could be easy, but I am not getting the problem.
I am using below code to rename the folders of document directory and is
working fine except one case.
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
}
Now, my problem is if 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.
I am not getting where the problem is.
No comments:
Post a Comment