Getting information about a physical device from a given file path

Suppose you have the full path to an available file or folder in the system. How can I get some unique identifier of the physical device on which the file (or folder) is actually located?

My first attempt was to use System.IO.DriveInfo, which depends on the presence of a drive letter. But UNC paths and multiple network drives mapped to the same physical device on the server add some complexity. For example, these 3 paths point to the same folder on the same device.

\\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 few paths and report the amount of free and free disk space on each device. I want to combine these 3 paths into one element in the report, not 3 separate elements.

Is there any Windows API that can help find this information in any arbitrary full path?

+3
source share
1 answer

In this win API call, you get what you need for disk space

  GetDiskFreeSpaceEx

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

In addition, to determine if all three mappings are on the same physical disk, call

GetVolumeInformation

and compare the serial numbers of the returned volumes

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

+2
source

Source: https://habr.com/ru/post/1697336/


All Articles