iOS: How do I rename a folder in the documents directory

filesystems, ios

Solution

If you move a file using `[NSFileManager moveItemAtPath:toPath:error:]` the source directory won't be deleted. If it was the only file, it will stay empty.

To rename a directory, you use the same command, just don't specify any files. For example:

NSError* error = [[NSError alloc] init];
[NSFileManager moveItemAtPath:@"/Images/" toPath:@"/OtherImages/" error:&error];

and the directory will be renamed to OtherImages and it will also keep all its contents.

Problem

I'm not sure if this is a silly question. If I move a file using `-[NSFileManger moveItemAtPath:toPath:error:]` from one place e.g. `/Images/image.png` to say `/OtherImages/image.png` will the old directory `/Images` be deleted automatically or will it still exist? Also, if I wanted to rename Images to Pictures could this be done in iOS or do I just have to move everything to a new path/url?

Original source