OSX:有没有办法以编程方式从垃圾箱中恢复文件?我尝试使用NSFileManager但它导致错误
NSFileManager* fm=[NSFileManager defaultManager];
NSError* err;
[fm copyItemAtPath:@"/Users/xyz/.Trash/abc.txt" toPath:@"/Users/xyz/Desktop/" error:&err];
NSLog(@"err:%@",err)
错误:
Error Domain=NSCocoaErrorDomain Code=516 "“abc.txt” couldn’t be copied to “Desktop” because an item with the same name already exists." UserInfo={NSSourceFilePathErrorKey=/Users/xyz/.Trash/abc.txt, NSUserStringVariant=(
Copy), NSDestinationFilePath=/Users/xyz/Desktop, NSFilePath=/Users/xyz/.Trash/abc.txt, NSUnderlyingError=0x610000041560 {Error Domain=NSPOSIXErrorDomain Code=17 "File exists"}}
答案 0 :(得分:0)
似乎为目标路径提供不同的名称可以解决问题
[fm copyItemAtPath:@"/Users/xyz/.Trash/abc.txt" toPath:@"/Users/xyz/Desktop/xyz.txt" error:&err];