Created
December 2, 2015 02:42
-
-
Save GaryLee/2043886ba495807335bb to your computer and use it in GitHub Desktop.
List Windows drives and types by win32file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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