2016-04-28 86 views
0

我想将用户的Mac桌面上的png文件移至安装的Windows文件共享。我似乎无法使远程路径与我使用的代码一起工作。Objective C - 将png文件写入远程文件共享

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"); 

我试过很多变种的远程文件路径。如果路径是本地的,我可以成功使用上面的代码。如何将文件移动到远程共享?

+1

我目前无法访问我的Mac,但是对于可能错误的内存,挂载的Windows网络文件夹正在挂载在/Volumes/NameofSharedResource/RestOfPath/foo.png下,因此请尝试从/ Volumes/... –

+0

在我尝试的许多排列中,我使用了/ Volumes。必须在当时有其他错误。感谢您指出了这一点。它使我重新审视它,现在它可以工作。 – FlameCoder

+0

太好了。很高兴我能帮上忙。对于其他人能够使用的答案,我会发布一个实际的答案,然后你的问题。 :) –

回答

1

Mac OS(OS X)与其他驱动程序一起加载网络驱动程序/Volumes。因此,你的代码应该是这个样子:

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"); 

注重与/Volumes

开始它现在应该工作的路径。