How can I get the name of a drive in python
Why don't you use win32api.GetVolumeInformation?
import win32api
win32api.GetVolumeInformation("C:\\")
outputs
('WINDOWS', 1992293715, 255, 65470719, 'NTFS')
Try the GetVolumeInformation
function instead. It returns the volume label directly.
Using the above fragment, I filled in the missing(optional, null) arguments as a quick helper:
import ctypes
kernel32 = ctypes.windll.kernel32
volumeNameBuffer = ctypes.create_unicode_buffer(1024)
fileSystemNameBuffer = ctypes.create_unicode_buffer(1024)
serial_number = None
max_component_length = None
file_system_flags = None
rc = kernel32.GetVolumeInformationW(
ctypes.c_wchar_p("F:\\"),
volumeNameBuffer,
ctypes.sizeof(volumeNameBuffer),
serial_number,
max_component_length,
file_system_flags,
fileSystemNameBuffer,
ctypes.sizeof(fileSystemNameBuffer)
)
print volumeNameBuffer.value
print fileSystemNameBuffer.value
This should be copy-and-paste-able.