gpt4 book ai didi

macos - 以编程方式了解给定路径是 Mac OS X 上的网络路径还是本地路径

转载 作者:行者123 更新时间:2023-12-03 16:14:09 25 4
gpt4 key购买 nike

如何在运行时以编程方式确定给定路径是 Mac OS X 上的网络路径还是本地路径?

例如:1./Volumes/abc/xyz(使用smb安装)2. ../test/pqr(应用程序位于共享网络路径上,因此当前工作目录也是网络路径,因此相对路径也是网络路径)

就像在 Windows 上一样,下面的代码将确定 pPath 是否是网络共享路径(如 * 1.\TallyDT100\c\test\file.txt2. z:\test\file.txt(z: 映射到某个网络路径时的网络路径)。

    UNIVERSAL_NAME_INFO   * universalname   = NULL;             ///< for getting the universal path name of file on network share.
DWORD retval; ///< for getting the return value from WNetGetUniversalName
DWORD length = MAX_PATH_LEN; ///< length of universal name which would be made.


// The memory for getting the universal name information is allocated.
universalname = (UNIVERSAL_NAME_INFO *) Calloc (MAX_PATH_LEN * sizeof (Char));

retval = WNetGetUniversalName (pPath, UNIVERSAL_NAME_INFO_LEVEL, universalname, &length);

Free (universalname);

// NO_ERROR is returned only when it's drive mapped for shared network folder.
return (NO_ERROR == retval) ? true : false;

最佳答案

如果有人通过 Google 搜索偶然发现这一点,以下是 Apple 提供的一些有用信息:

There are numerous ways to test whether a volume is a network volume. The best method to use depends on the layer that you're working at:

If you're working on general application code, you should use NSURL for this. Construct a URL for any item on the volume and then call -getResourceValue:forKey:error: to get the NSURLVolumeIsLocalKey key; the returned value will be false (kCFBooleanFalse) for a network volume and true (kCFBooleanTrue) for a local volume.

If you're programming at the BSD layer, you can call statfs and test the MNT_LOCAL flag in the f_flags field that it returns. Alternatively, you can call getattrlist to request the ATTR_VOL_MOUNTFLAGS attribute, which can be more efficient than statfs under some circumstances.

https://developer.apple.com/library/mac/qa/nw09/_index.html

关于macos - 以编程方式了解给定路径是 Mac OS X 上的网络路径还是本地路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19449511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com