NSFILEMANAGER -COPYITEMATPATH:Topath:エラー:読み取り専用フォルダーで失敗
-
29-09-2019 - |
質問
読み取り専用のフォルダーをコピーしようとしていますが、その内部にファイルを別の場所にコピーしようとしています。 -copyitematpath:topath:error:ファイルをコピーしますが、ファイルはコピーしません。エラーを示すサンプルコードは以下にあります。
この場合、コピーする前にフォルダーの権限を変更することはオプションではありません。
誰かが提案を提供できますか?
エラーは次のとおりです。
エラードメイン= nsposixerrordomainコード= 13 userinfo = 0x1001102a0 "操作は完了できませんでした。許可拒否"
エラーのuserinfoは次のとおりです。{
nsdestinationFilepath = "/users/xxxxxxx/desktop/readonlyfilecopy/testdir/abbey road.jpg";
nsfilepath = "/users/xxxxxxx/desktop/testdir/abbey road.jpg";
nsuserstringvariant = copy;
}
#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;
}
解決
フォルダー内のすべてのファイルを読み取ることができると確信していますか?もしそうなら、これは実際にはココアのバグかもしれません。新しいフォルダーを作成し、読み取り専用に設定し、ファイルをフォルダーにコピーしようとする可能性があります。小さなテストケースでこれを再現できる場合は、 バグを送信します リンゴに。
所属していません StackOverflow