iphone - 如何重命名目录?

标签 iphone objective-c nsfilemanager

我在我的应用程序目录的 Documents 文件夹中创建了一个文件夹。

我想通过代码重命名该文件夹,但无法理解该怎么做。

请帮帮我。

最佳答案

你试过吗?

    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
    }

关于iphone - 如何重命名目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486979/

相关文章:

ios - 权利文件与您的配置文件中指定的不匹配。(0xE8008016)

ios - 如何添加一个覆盖所有其他 View (包括导航栏和状态栏)的黑屏?

ios - 在 Objective-C 中加载时将光标移动到预填充 Textview 的开头

cocoa - 目标-C : Programmatically set file privileges to current user

objective-c - 有没有比我的实现更好的方法来检查更新的文件?

ios - fileManager.createFileAtPath 总是失败

iphone - 为什么设置 MBProgressHUD hide 为 YES,而 Hidden method 为 NO?

iphone - 导航栏的自定义背景图像 - 大小调整和后退按钮着色

ios - OpenGL ES 1.1 iPhone5+ IOS 8 黑屏

objective-c - 在 macOS 上,是否可以修改已编译的动态库的符号名称?