tags:

views:

249

answers:

1

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. But UNC paths and multiple network drives mapped to the same physical device on a server add some complications. For example these 3 paths all 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 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.

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

+1  A: 

This win API call should get you what you need regarding disk space

  GetDiskFreeSpaceEx

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

curtisk
But when I pass each of those 3 paths in my question to this function, I'll get 3 answers -- yes they will all be the same but how can I know for sure that they all reside on the same physical device?
Brian Ensink
then call GetVolumeInformation first and do a comparison on the volume serial numbers to determine if you are dealing with the same disk.http://msdn.microsoft.com/en-us/library/aa364993(VS.85).aspx
curtisk