问题描述
我遇到了一个问题,获取一个文件的完整网址 FSCopyURLForVolume
。我正在使用此问题的代码从文件URL确定AFP共享但它不给我完整的网址。例如:
使用以下路径: /Volume/server/html/index.html
所有我回来的是url到基本mount: nfs:// real_server_name / vol
叶子目录和文件名已被关闭,完整路径在文件信息中可用,因此必须有一种方法来获取此信息。
编辑:
经过一些挖掘似乎想使用 kFSCatInfoParentDirID
和 kFSCatInfoNodeID
来获取父节点和节点(文件)id,但我不知道如何将它变成有用的东西。
NSError * error = nil; //错误
NSURL * volumePath = nil; // result of UNC network mounting path
NSString * testPath = @/ Volumes / SCAMBIO / testreport.exe; //文件路径测试
NSURL * testUrl = [NSURL fileURLWithPath:testPath]; //从文件路径创建NSURL
NSString * mountPath = [testPath stringByDeletingLastPathComponent]; //只获取加载的卷部分,即/ Volumes / SCAMBIO
NSString * pathComponents = [testPath substringFromIndex:[mountPath length]]; //获取在加载路径后开始的其余路径,即/testereport.exe
[testUrl getResourceValue:& volumePath forKey:NSURLVolumeURLForRemountingKey error:& error]; //获取真正的UNC网络路径,即smb:// ....
NSLog(@Path:%@%@,volumePath,pathComponents); //将结果写入调试控制台
结果是在我的case,
路径: strong> smb://[email protected]/SCAMBIO/testreport.exe
您需要指定网络映射卷。
ciao。
I am running into an issue getting the full url for a file with FSCopyURLForVolume
. I am using the code from this issue Determine AFP share from a file URL but it isn't giving me the full url. For example:
With a path like: /Volume/server/html/index.html
All I get back is url to the base mount: nfs://real_server_name/vol
Leaf directories and the file names are left off, the full path is available in the files info so there has to be a way to get this information.
EDIT:
After some more digging is seems like I want to use kFSCatInfoParentDirID
and kFSCatInfoNodeID
to get the parent and node(file) id but I'm not sure how to turn this into something useful.
because the FSPathMakeRef, FSGetCatalogInfo and FSCopyURLForVolume are deprecated from Mac OS X 10.8 I modernised the code for get UNC network path on Mac OS X mounted volumes.
NSError *error=nil; //Error
NSURL *volumePath=nil; //result of UNC network mounting path
NSString* testPath =@"/Volumes/SCAMBIO/testreport.exe"; //File path to test
NSURL *testUrl = [NSURL fileURLWithPath:testPath]; //Create a NSURL from file path
NSString* mountPath = [testPath stringByDeletingLastPathComponent]; //Get only mounted volume part i.e. /Volumes/SCAMBIO
NSString* pathComponents = [testPath substringFromIndex:[mountPath length]]; //Get the rest of the path starting after the mounted path i.e. /testereport.exe
[testUrl getResourceValue:&volumePath forKey:NSURLVolumeURLForRemountingKey error:&error]; //Get real UNC network mounted path i.e. smb://....
NSLog(@"Path: %@%@", volumePath,pathComponents); //Write result to debug console
The result is in my case,Path: smb://[email protected]/SCAMBIO/testreport.exe
You need to specify your network mapped volume.
ciao.
这篇关于来自FSCopyURLForVolume的完整网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!