Skip to content

Instantly share code, notes, and snippets.

@GaryLee
Created December 2, 2015 02:42
Show Gist options
  • Save GaryLee/2043886ba495807335bb to your computer and use it in GitHub Desktop.
Save GaryLee/2043886ba495807335bb to your computer and use it in GitHub Desktop.
List Windows drives and types by win32file.
#!python
# coding: utf-8
import win32api
import win32file
# Available driver types:
# win32file.DRIVE_UNKNOWN => 0
# win32file.DRIVE_NO_ROOT_DIR => 1
# win32file.DRIVE_REMOVABLE => 2
# win32file.DRIVE_FIXED => 3
# win32file.DRIVE_REMOTE => 4
# win32file.DRIVE_CDROM => 5
# win32file.DRIVE_RAMDISK => 6
drive_type_strings = {
win32file.DRIVE_UNKNOWN : 'UNKNOWN',
win32file.DRIVE_NO_ROOT_DIR : 'NO_ROOT_DIR',
win32file.DRIVE_REMOVABLE : 'REMOVABLE',
win32file.DRIVE_FIXED : 'FIXED',
win32file.DRIVE_REMOTE : 'REMOTE',
win32file.DRIVE_CDROM : 'CDROM',
win32file.DRIVE_RAMDISK : 'RAMDISK',
}
drives = (drive for drive in win32api.GetLogicalDriveStrings().split("\000") if drive)
for drive in drives:
drive_type = win32file.GetDriveType(drive)
print "%s\t%s(%d)" % (drive, drive_type_strings[drive_type], drive_type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment