Rename file in Cocoa?

前端 未结 5 1290
再見小時候
再見小時候 2021-01-01 11:11

How would I rename a file, keeping the file in the same directory?

I have a string containing a full path to a file, and a string containing a the new filename (and

5条回答
  •  旧时难觅i
    2021-01-01 11:49

    here's a more recent example for iOS, the NSFileManager method is a little different:

    NSString *newFilename = [NSString stringWithFormat:@"%@.m4a", newRecording.title];
    
    NSString *newPath = [[newRecording.localPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:newFilename];
    [[NSFileManager defaultManager] moveItemAtPath:newRecording.localPath toPath:newPath error:nil];
    

提交回复
热议问题