0

I want to move a png file from user's Mac desktop to a mounted Windows file share. I can't seem to be able to make the remote path work with the code I'm using.

NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];

 if ([filemgr copyItemAtPath: stringFilePath  toPath: @"/NameOfFileShare/Path/To/Folder/FileName.png" error: NULL]  == YES)
 NSLog (@"Copy successful");
 else
 NSLog (@"Copy failed");

I've tried many variations of the remote file path. I can use the code above successfully if paths are local. How can I move a file to a remote share???

Rojan Gh.
  • 1,062
  • 1
  • 9
  • 32
FlameCoder
  • 49
  • 1
  • 8
  • 1
    I don't have access to my Mac right now but to my memory which might be wrong, the mounted windows network folders are being mounted under /Volumes/NameofSharedResource/RestOfPath/foo.png, therefore try accessing from /Volumes/... – Rojan Gh. Apr 28 '16 at 12:17
  • Could of sworn I used /Volumes in my many permutations of trying. Must of had something else wrong at the time. Thanks for pointing that out. It made me revisit it and it now works. – FlameCoder Apr 28 '16 at 16:13
  • Great. Happy I could help. For others to be able to use the answer I will post an actual answer to your question then. :) – Rojan Gh. Apr 28 '16 at 18:58

1 Answers1

1

Mac OS (OS X) loads the network drivers under /Volumes alongside other drivers. Therefore your code should look something like this:

NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];

if ([filemgr copyItemAtPath: stringFilePath  toPath: @"/Volumes/NameOfFileShare/Path/To/Folder/FileName.png" error: NULL]  == YES)
NSLog (@"Copy successful");
else
NSLog (@"Copy failed");

Pay attention to the path that starts with /Volumes

It should work now.

Rojan Gh.
  • 1,062
  • 1
  • 9
  • 32