PDA

View Full Version : NSFileManager's method copyItemAtPath fails while copying folder from USB to Desktop.




goyalpk
Dec 8, 2009, 02:11 PM
Hi there,

NSFileManager's method copyItemAtPath fails while copying folder from USB flash drive to Desktop.

Error description is :

Error Domain=NSPOSIXErrorDomain Code=1 UserInfo=0x10df30 "Operation could not be completed. Operation not permitted"

Actually it creates folder on Desktop but not the files inside the source folder.

Is it because of permission difference for file in USB flash drive and the file which needs to be created on Desktop?

Code is:


NSString *srcPath = @"/Volumes/USB DRIVE/hello123";
NSString *destPath = @"/Users/Pankaj/Desktop/hello123";
NSFileManager *fm = [NSFileManager defaultManager];

BOOL isCopySuccess = NO;

NSError *err;
isCopySuccess = [fm copyItemAtPath:srcPath toPath:destPath error:&err];

if(isCopySuccess)
NSLog(@"copy successfull");
else
{
NSLog(@"copy failed");
NSLog(@"%@", [err description]);


}

Thanks so much in advance.
Pankaj



chown33
Dec 8, 2009, 06:06 PM
You're the only one who can say whether it's a permission problem or not. None of us out here can see what's on your flash drive, nor can we run your program using your Desktop folder.

Revise your code to do more than just print the error's description. Get the error's userInfo dictionary and examine the keys and values for details on what caused the error.

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSError_Class/Reference/Reference.html#//apple_ref/occ/instm/NSError/userInfo