Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename directories?

I have created a folder within the Documents folder in my application directory .

I wanted to rename that folder through code,but not able to understand how to do it.

Please help me out.

like image 440
iPhoneDev Avatar asked Dec 20 '10 04:12

iPhoneDev


1 Answers

Have you tried?

    NString *newDirectoryName = @"<new folder name>";    
    NSString *oldPath = @"<path to the old folder>";
    NSString *newPath = [[oldPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newDirectoryName];
    NSError *error = nil;
    [[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:newPath error:&error];
    if (error) {
        NSLog(@"%@",error.localizedDescription);
        // handle error
    }
like image 112
mackross Avatar answered Jan 17 '23 18:01

mackross