user1232989
user1232989

Reputation: 11

Renaming A Plist In Objective-C

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

Answers (2)

Tark
Tark

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

Parag Bafna
Parag Bafna

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

Related Questions