且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何重命名 Documents 目录中的文件?

更新时间:2023-09-27 23:18:58

获取 NSDocuments 目录使用:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"MyFile.txt"];

如何重命名您可以在此处找到的文件:

How to rename file you can find here:

如何使用 NSFileManager 重命名文件

如果您不知道文档目录中文件的名称,您可以使用:

If you do not know the names of the files in documents directory you can use :

NSArray *directoryContent = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];

该数组包含您需要的所有文件名.所以你可以重命名它们.

This array contains all filenames you need. So you can rename them all.