John P
John P

Reputation: 625

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

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?

Upvotes: 3

Views: 3758

Answers (1)

gregorkas
gregorkas

Reputation: 137

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.

Upvotes: 8

Related Questions