从 UNC 路径检索服务器名称
Windows 中是否有从 UNC 路径检索服务器名称的 api? (\\服务器\共享)
还是我需要自己做?
我找到了 PathStripToRoot 但它没有解决问题。
Is there an api in windows that retrieves the server name from a UNC path ? (\\server\share)
Or do i need to make my own ?
I found PathStripToRoot but it doesn't do the trick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道用于解析 UNC 路径的 Win32 API; 但是您应该检查:
\\computername\share
\\?\UNC\computername\share
(人们使用它来访问超过 260 个字符的长路径)smb://computername/share
和这种情况hostname:/directorypath/resource
阅读此处了解更多信息
I don't know of a Win32 API for parsing a UNC path; however you should check for:
\\computername\share
\\?\UNC\computername\share
(people use this to access long paths > 260 chars)smb://computername/share
and this casehostname:/directorypath/resource
Read here for more information
这是未经测试的,但也许 PathIsUNC() 和 PathFindNextComponent() 的组合可以解决这个问题。
This is untested, but maybe a combination of PathIsUNC() and PathFindNextComponent() would do the trick.
我不知道是否有专门的 API,我可能会自己实现简单的字符串处理(跳过“\\”或返回 null,查找下一个 \ 或字符串末尾并返回该子字符串)首先调用 PathIsUNC()
I don't know if there is a specific API for this, I would just implement the simple string handling on my own (skip past "\\" or return null, look for next \ or end of string and return that substring) possibly calling PathIsUNC() first
如果您将以纯文本形式接收数据,您应该能够使用简单的正则表达式来解析它,不确定您使用什么语言,但我倾向于使用 perk 进行这样的快速搜索。 假设您有一个包含多行的大文档,每行包含一个路径,您可以在 \\ 的 Ie 上搜索
m/\\\\([0-9][0-9][0-9]\.(重复3次,当然不记得ip地址要求,你可能需要修改第一个) then\\ )? 为了使其可选并包含尾部斜杠,最后是 (.*)\\/ig 它很粗糙,但应该可以解决问题,并且路径名应该在 $2 中以供使用!
我希望这已经足够清楚了!
If you'll be receiving the data as plain text you should be able to parse it with a simple regex, not sure what language you use but I tend to use perk for quick searches like this. Supposing you have a large document containing multiple lines containing one path per line you can search on \\'s I.e
m/\\\\([0-9][0-9][0-9]\.(repeat 3 times, of course not recalling ip address requirements you might need to modify the first one for sure) then\\)? To make it optional and include the trailing slash, and finally (.*)\\/ig it's rough but should do the trick, and the path name should be in $2 for use!
I hope that was clear enough!