Reputation: 11
I want to rename a plist file in Objective-C which is used to save data. Here is how I defined the path for the plist file:
- (NSString *)save {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[path objectAtIndex:0] stringByAppendingPathComponent:@"save.plist"];
}
How can I rename this file? Thanks.
Upvotes: 0
Views: 329
Reputation: 5175
so you have a plist file in an xcode project and you want to rename it? what is stopping you just renaming it in the project navigator?
EDIT:
if the plist is generated dynamically, then just load the plist and save it again with the new name.
Upvotes: 0
Reputation: 22930
use NSFileManager moveItemAtPath:toPath:error:
method.
NSError *error;
[[NSFileManager defaultManager] movePath:oldPath toPath:newPath error:&error];
For Example:
NSArray *path =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *oldPath = [[path objectAtIndex:0] stringByAppendingPathComponent:@"save.plist"];
NSString *newpath = [[path objectAtIndex:0] stringByAppendingPathComponent:@"new.plist"];
Upvotes: 1