开发者

NSFileManager -copyItemAtPath:toPath:error: fails with read-only folder

I'm trying to copy a folder that is read-only, but has files inside it, to another location. When I use -copyItemAtPath:toPath:error: it copies the folder, but not the files. Sample code that demonstrates the error is below.

Changing the permissions of the folder before copying is not an option in this case.

Can anyone offer a suggestion?

The error is:

Error Domain=NSPOSIXErrorDomain Code=13 UserInfo=0x1001102a0 "The operation couldn’t be completed. Permission denied"

The error's userInfo is: {

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]);
    }

    [开发者_如何学Pythonpool drain];
    return 0;
}


Are you certain you can read every single file in the folder. If so, then this may actually be a Cocoa bug. It's entirely possible that it's creating a new folder, setting it read-only, and then attempting to copy files into the folder. If you can reproduce this in a small test-case, you should submit a bug to apple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜