How to rename a file using NSFileManager

后端 未结 4 1686
[愿得一人]
[愿得一人] 2020-12-24 05:51

I have a single file named a.caf in the documents directory. I would like to rename it when user types into a UITextField and presses change (t

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 06:01

    You can use moveItemAtPath.

    NSError * err = NULL;
    NSFileManager * fm = [[NSFileManager alloc] init];
    BOOL result = [fm moveItemAtPath:@"/tmp/test.tt" toPath:@"/tmp/dstpath.tt" error:&err];
    if(!result)
        NSLog(@"Error: %@", err);
    [fm release];
    

提交回复
热议问题