我正在尝试将只读但其中包含文件的文件夹复制到另一个位置。当我使用 -copyItemAtPath:toPath:error: 它复制文件夹,但不复制文件。演示错误的示例代码如下。
在这种情况下,不能在复制之前更改文件夹的权限。
任何人都可以提供建议吗?
错误是:
Error Domain=NSPOSIXErrorDomain Code=13 UserInfo=0x1001102a0“操作无法完成。权限被拒绝”
错误的 userInfo 是: {
NSDestinationFilePath = "/Users/xxxxxxx/Desktop/readonlyfilecopy/testdir/Abbey Road.jpg";
NSFilePath = "/Users/xxxxxxx/Desktop/testdir/Abbey Road.jpg";
NSUserStringVariant = 复制;
}
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* src = @"/Users/xxxxxxx/Desktop/testdir";
NSString* target = @"/Users/xxxxxxx/Desktop/readonlyfilecopy/testdir";
NSError* error = nil;
[[NSFileManager defaultManager] copyItemAtPath:src toPath:target error:&error];
if (error) {
NSLog(@"%@", error);
NSLog(@"%@", [error userInfo]);
}
[pool drain];
return 0;
}