我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用win32api.GetVolumeInformation()。
def isNTFSVolume(self, driveletter): """Boolean indicating whether a volume is NTFS @param driveletter: The letter of the drive to check @type driveletter: string """ # Strip away : / \ while driveletter.endswith(":") or driveletter.endswith("\\") or driveletter.endswith("/"): driveletter = driveletter[:-1] if not len(driveletter) == 1: raise ValueError( "Wrong parameter for WindowsSystem.isNTFSVolume: [%s] is not a valid drive letter." % driveletter) fTest = '%s:\\' % driveletter volumeInformation = win32api.GetVolumeInformation(fTest) fileSystem = volumeInformation[4] result = fileSystem == 'NTFS' return result
def __is_cd_inserted(self, drive=''): try: x = win32api.GetVolumeInformation(drive) #print "CD is inserted in drive %s" % drive return 1 except: #print "no CD inserted in drive %s" % drive return 0
def DriveNameToPath(drive): if os.name=='nt': import win32api namePaths = { win32api.GetVolumeInformation(i)[0].lower():i for i in win32api.GetLogicalDriveStrings().split('\0') if i } drive = drive.lower() if drive not in namePaths: raise ValueError('Drive name "%s" not found' % drive) return namePaths[drive] else: raise NotImplementedError # todo: do something with /media/XXX here for ubuntu
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