Search code examples
pythonpywin32

How can I get the NT name of a partition in python (Windows)?


How can I get the NT name of a partition in python? Or at least a list of all the names in the system?

What I have: a drive letter or a label, or some other identifier of the partition (for example, the letter E:, or label "Data")

What I need: a name like "\\?\\HarddiskVolume12" that corresponds to this partition.

Before anyone asks, yes, I really need it.

The thing is that I need to be able to address partitions with and without letters assigned to them, so the best solution would be to get a list of some kind of objects that have all the IDs, nt names, letters as attributes, and then, based on these, I can choose the partitions that I need for my purposes.

P.S. I tried using FindFirstVolume/FindNextVolume from the winsys._kernel32 module, but that returns some kind of ID with a GUID in it... Not exactly what I want.


Solution

  • import win32file
    
    win32file.QueryDosDevice('E:')