假设我在路径/documents/recording.caf 中有一个文件,我想将它复制到文件夹/documents/folder 中。我该怎么做?如果我想使用以下代码,似乎我必须在路径中包含文件名和扩展名,我并不总是知道。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newPath = [documentsDirectory stringByAppendingPathComponent:@"/temporary/recording.caf"];
if ([fileManager fileExistsAtPath:newPath] == NO) {
[fileManager copyItemAtPath:file toPath:newPath error:&error];
}
}
表格视图会使用它在目录中找到的每个文件进行更新,如果用户点击一个单元格,我想将此文件复制到其他地方。