如何检查文件是否位于 Windows 网络共享上?
我需要检查文件是否通过网络访问。我正在检查的值 GetFileAttributes("\\\\Foo\\Bar\\foobar.txt") & FILE_ATTRIBUTE_OFFLINE
但它从未设置。实现这一目标的更稳健的方法是什么?
I need to check if files are accessed through the network. I'm checking the value ofGetFileAttributes("\\\\Foo\\Bar\\foobar.txt") & FILE_ATTRIBUTE_OFFLINE
but it's never set. What is the more robust way to achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
脱机是一种特殊的文件状态,您也可以将其设置为网络文件,但必须自行设置。并非每个脱机文件都会自动标记为脱机使用。我认为资源管理器上甚至有一个用于离线文件的特殊覆盖图标(黑色时钟?)。
我认为使用 PathIsNetworkPath() 您可以检查文件是否在网络上。
Offline is a special file status that you can also set to on network files but you have to set it yourself. Not every offline file is automatically marked for offline use. I think there even is a special overlay icon on explorer for offline files (a black clock?).
I think that with
PathIsNetworkPath()
you can check that the file is on the network.调用 GetVolumePathName,然后调用 GetDriveType。
如果指定了网络共享,则 GetVolumePathName 返回 GetDriveType 返回 DRIVE_REMOTE 的最短路径。
call GetVolumePathName and then GetDriveType.
If a network share is specified, GetVolumePathName returns the shortest path for which GetDriveType returns DRIVE_REMOTE.