【问题标题】:OSX: Moving a file from Trash to its previous location programmaticallyOSX:以编程方式将文件从垃圾箱移动到其先前的位置
【发布时间】:2015-10-16 17:31:00
【问题描述】:

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"}}

【问题讨论】:

标签: macos nsfilemanager recycle-bin


【解决方案1】:

似乎为目标路径提供不同的名称可以解决问题

[fm copyItemAtPath:@"/Users/xyz/.Trash/abc.txt" toPath:@"/Users/xyz/Desktop/xyz.txt" error:&err];

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 2018-12-31
    • 2014-06-18
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    相关资源
    最近更新 更多