本文整理汇总了Python中win32file.GetDriveType方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.GetDriveType方法的具体用法?Python win32file.GetDriveType怎么用?Python win32file.GetDriveType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32file
的用法示例。
在下文中一共展示了win32file.GetDriveType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findAvailableDrives
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def findAvailableDrives():
return [(d, win32file.GetDriveType(d)) for d in
win32api.GetLogicalDriveStrings().rstrip('\0').split('\0')]
示例2: findVolumeGuids
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def findVolumeGuids():
DiskExtent = collections.namedtuple(
'DiskExtent', ['DiskNumber', 'StartingOffset', 'ExtentLength'])
Volume = collections.namedtuple(
'Volume', ['Guid', 'MediaType', 'DosDevice', 'Extents'])
found = []
h, guid = FindFirstVolume()
while h and guid:
#print (guid)
#print (guid, win32file.GetDriveType(guid),
# win32file.QueryDosDevice(guid[4:-1]))
hVolume = win32file.CreateFile(
guid[:-1], win32con.GENERIC_READ,
win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE,
None, win32con.OPEN_EXISTING, win32con.FILE_ATTRIBUTE_NORMAL, None)
extents = []
driveType = win32file.GetDriveType(guid)
if driveType in [win32con.DRIVE_REMOVABLE, win32con.DRIVE_FIXED]:
x = win32file.DeviceIoControl(
hVolume, winioctlcon.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
None, 512, None)
instream = io.BytesIO(x)
numRecords = struct.unpack('<q', instream.read(8))[0]
fmt = '<qqq'
sz = struct.calcsize(fmt)
while 1:
b = instream.read(sz)
if len(b) < sz:
break
rec = struct.unpack(fmt, b)
extents.append( DiskExtent(*rec) )
vinfo = Volume(guid, driveType, win32file.QueryDosDevice(guid[4:-1]),
extents)
found.append(vinfo)
guid = FindNextVolume(h)
return found
示例3: check_drives
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def check_drives():
for drive in win32api.GetLogicalDriveStrings().split("\x00"):
sys.stdout.write(".")
type = win32file.GetDriveType(drive)
if type == win32con.DRIVE_FIXED:
fs = win32api.GetVolumeInformation(drive)[4]
if fs == 'NTFS':
warning = ""
weak_perms = check_weak_write_perms(drive, 'directory')
if weak_perms:
# print "Weak permissions on drive root %s:" % drive
# print_weak_perms('directory', weak_perms)
sys.stdout.write(".")
save_issue("WPC010", "writable_drive_root", weak_perms)
elif fs == 'FAT':
save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT does not support file permissions)" )
sys.stdout.write("!")
elif fs == 'FAT32':
save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT32 does not support file permissions)" )
sys.stdout.write("!")
else:
warning = " (not NTFS - might be insecure)"
save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (Not NTFS - might not be secure)" )
sys.stdout.write("!")
# print "Fixed drive %s has %s filesystem%s" % (drive, fs, warning)
print
示例4: get_local_drives
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def get_local_drives():
"""Returns a list containing letters from local drives"""
drive_list = win32api.GetLogicalDriveStrings()
drive_list = drive_list.split("\x00")[0:-1] # the last element is ""
list_local_drives = []
for letter in drive_list:
if win32file.GetDriveType(letter) == win32file.DRIVE_FIXED:
list_local_drives.append(letter)
return list_local_drives
示例5: get_removable_drives
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def get_removable_drives():
"""Returns a list containing letters from removable drives"""
drive_list = win32api.GetLogicalDriveStrings()
drive_list = drive_list.split("\x00")[0:-1] # the last element is ""
list_removable_drives = []
for letter in drive_list:
if win32file.GetDriveType(letter) == win32file.DRIVE_REMOVABLE:
list_removable_drives.append(letter)
return list_removable_drives
示例6: getFilesHash
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def getFilesHash():
ret = []
# List logical drives
drives = win32api.GetLogicalDriveStrings().split('\x00')
drives.pop()
# Only get local dries
drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ]
# List files
for drive in drives:
hashRec(drive)
示例7: getFiles
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def getFiles():
ret = []
# List logical drives
drives = win32api.GetLogicalDriveStrings().split('\x00')
drives.pop()
# Only get local dries
drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ]
# List files
for drive in drives:
print os.popen('dir /s /b '+drive).read()
示例8: is_optical_drive
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetDriveType [as 别名]
def is_optical_drive(self, drive_letter):
'''
@summary: Checks if the specified drive letter is an optical drive
@param drive_letter: The letter of the drive to check
@return: True if drive is an optical drive, otherwise false
'''
if win32file.GetDriveType('%s:' % drive_letter) == win32file.DRIVE_CDROM:
return True
else:
return False