简体   繁体   English

从给定文件路径获取有关物理设备的信息

[英]Obtaining information about the physical device from a given file path

Suppose you have a full path to an accessible file or folder on the system. 假设您具有系统上可访问文件或文件夹的完整路径。 How can I get some kind of unique identifier for the physical device that the file (or folder) actually resides on? 如何为文件(或文件夹)实际驻留的物理设备获取某种唯一标识符?

My first attempt was to use System.IO.DriveInfo which depends on having a drive letter. 我的第一次尝试是使用System.IO.DriveInfo ,这取决于有一个驱动器号。 But UNC paths and multiple network drives mapped to the same physical device on a server add some complications. 但UNC路径和多个网络驱动器映射到服务器上的同一物理设备会增加一些复杂性。 For example these 3 paths all point to the same folder on the same device. 例如,这3条路径都指向同一设备上的同一文件夹。

\\myserver\users\brian\public\music\
s:\users\brian\public\music\          (here s:\ is mapped to \\myserver\)
u:\public\users\music\                (here u:\ is mapped to \\myserver\users\brian\)

Ultimately my goal is to take these multiple paths and report the amount of used and free disk space on each device. 最终,我的目标是采用这些多路径并报告每台设备上已用和可用磁盘空间的数量。 I want to combine these 3 paths into a single item in the report and not 3 separate items. 我想将这3个路径组合到报表中的单个项目中,而不是3个单独的项目。

Is there any Windows API that can help find this information given any arbitrary full path? 是否有任何Windows API可以帮助在任意完整路径下找到此信息?

This win API call should get you what you need regarding disk space 这个win API调用可以为您提供有关磁盘空间的所需信息

  GetDiskFreeSpaceEx

http://msdn.microsoft.com/en-us/library/aa364937(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa364937(VS.85).aspx

Also, to determine if the three mappings all are from the same physical disk, perform a call to 此外,要确定三个映射是否都来自同一物理磁盘,请执行调用

GetVolumeInformation

and compare the returned volume serial numbers 并比较返回的卷序列号

http://msdn.microsoft.com/en-us/library/aa364993(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa364993(VS.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM