def get_volume_information(volume): # If it's a UNC path, raise an error. if not volume: raise UnsupportedFileSystemError( "Only files with a Local File System path can be wiped.") result1 = GetVolumeInformation(volume) result2 = GetDiskFreeSpace(volume) result3 = GetDriveType(volume) for drive_enum, error_reason in [(DRIVE_REMOTE, "a network drive"), (DRIVE_CDROM, "a CD-ROM"), (DRIVE_UNKNOWN, "an unknown drive type")]: if result3 == drive_enum: raise UnsupportedFileSystemError( "This file is on %s and can't be wiped." % error_reason) # Only NTFS and FAT variations are supported. # UDF (file system for CD-RW etc) is not supported. if result1[4].upper() == "UDF": raise UnsupportedFileSystemError( "This file system (UDF) is not supported.") volume_info = namedtuple('VolumeInfo', [ 'drive_name', 'max_path', 'file_system', 'sectors_per_cluster', 'bytes_per_sector', 'total_clusters' ]) return volume_info(result1[0], result1[2], result1[4], result2[0], result2[1], result2[3])
def checkfs(self, method): from win32api import GetVolumeInformation from win32file import GetVolumePathName src_volume = GetVolumePathName(self.src) dst_volume = GetVolumePathName(self.dst) if method == M_HARDLINK and src_volume != dst_volume: return 'Hard links can be created only within a single logical drive' errmsg = 'File system on drive {0} does not support {0} links' src_fs = GetVolumeInformation(src_volume)[-1] dst_fs = GetVolumeInformation(dst_volume)[-1] if src_fs != FS_NTFS: return errmsg.format(src_volume, self.link_method_names[method]) if dst_fs != FS_NTFS: return errmsg.format(dst_volume, self.link_method_names[method]) return None
def getVolumeLabel(drive): ''' Reads in a disk drive ("D:\\") and returns its volume label. ''' # Return name of movie from DVD Drive. volume_information = GetVolumeInformation(drive) volume_label = volume_information[0] return volume_label
def get_removable_drives(drive_types=(win32con.DRIVE_REMOVABLE, )): ret = list([" "]) drives_str = GetLogicalDriveStrings() drives = [item for item in drives_str.split("\x00") if item] for drive in drives: if GetDriveType(drive) in drive_types: try: GetVolumeInformation(drive[:2] + "\\") ret.append(drive[:2]) except: pass #print("Removable Drives: " + str(ret)) return ret
def hdd_drive_check(drive, raise_exception=False): """ check if label of passed drive name is following naming convention (see module docu above) :param drive: Windows drive name (like 'c:\\') :type drive: str :param raise_exception: set to True if a ValueError should be thrown in case of missing the convention :type raise_exception: bool :return: check result: True if naming convention is confirmed :rtype: bool """ try: name = GetVolumeInformation(drive)[0] except win_error: name = "NoDriveAvailable" return hdd_label_check(name, raise_exception=raise_exception)
def refreshdrives(*args): global rdrives rdrives = get_removable_drives() rdrivenames = [] for i in rdrives: rdrivenames.append(i) rdrivesfordeletion = [] for i in range(len(rdrives)): try: rdrivenames[i] = GetVolumeInformation( rdrivenames[i] + "\\")[0] + " (" + rdrivenames[i] + ")" except: pass #print(rdrivenames) InputComboBox['values'] = tuple(rdrivenames) if len(rdrivenames) > 1: InputComboBox.current(1) else: InputComboBox.current(0)
def getVolumeInfo(path): if sys.platform == 'win32': #or sys.platform == 'cygwin': from win32api import GetVolumeInformation path = os.path.abspath(path) assert path[1]==':', 'unc not supported yet' #todo drive = path[:3] #todo: If you are attempting to obtain information about a floppy drive that does not have a floppy disk or a CD-ROM drive that does not have a compact disc, the system displays a message box asking the user to insert a floppy disk or a compact disc, respectively. To prevent the system from displaying this message box, call the SetErrorMode function with SEM_FAILCRITICALERRORS. volumeName, volSerialNumber, maxFileLength, flags, fs = GetVolumeInformation(drive) import win32file driveType = win32file.GetDriveType(drive) driveTypemap = { win32file.DRIVE_UNKNOWN : 'unknown', win32file.DRIVE_NO_ROOT_DIR : 'unknown', win32file.DRIVE_REMOVABLE : 'removable', win32file.DRIVE_FIXED : 'local', win32file.DRIVE_REMOTE : 'remote', win32file.DRIVE_CDROM : 'removable', win32file.DRIVE_RAMDISK : 'local' } volumeType = driveTypemap[driveType] return volumeName, volumeType, volSerialNumber else: assert 0, 'NYI!' #todo
def getRemovableDevices(): removableDevices = [] if sys.platform == "win32": from win32api import GetLogicalDriveStrings, GetVolumeInformation from win32file import GetDriveType drives = GetLogicalDriveStrings() drives = drives.split('\000')[:-1] for drive in drives: if GetDriveType(drive) == 2: try: removableDevices.append( list(GetVolumeInformation(drive)) + [drive]) except: QgsMessageLog.logMessage("GetVolumeInformation error ", u'qgis2mobile', QgsMessageLog.CRITICAL) else: pass return removableDevices
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import win32con from win32api import GetLogicalDriveStrings, GetVolumeInformation from win32file import GetDriveType #define TEST='removable drives' def get_drives_list(drive_types=(win32con.DRIVE_REMOVABLE, )): drives_str = GetLogicalDriveStrings() drives = [item for item in drives_str.split("\x00") if item] return [ item[:2] for item in drives if drive_types is None or GetDriveType(item) in drive_types ] if __name__ == "__main__": drives = get_drives_list(drive_types=(win32con.DRIVE_REMOVABLE, )) print(TEST) for drive in drives: info = GetVolumeInformation(drive) print('{} {}'.format(drive, info[0]))
if __name__ == '__main__': map_user = dict() for row in open("config.ini", 'rb').readlines(): if row == "": continue parts = line_to_tuple(str(row, encoding="utf-8")) map_user[parts[0]] = parts[1] app = QApplication(sys.argv) import ctypes ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid") window = MyWindow(map_user["name"], map_user["passwd"], map_user["QQ"]) window.show() if "Code" in map_user: tuple = GetVolumeInformation("c:\\") machine_code = "" for em in tuple[1:-1]: machine_code += str(em) register_code = DesEncrypt(machine_code) register_code = str(register_code, encoding="utf-8") print(register_code) if register_code != map_user.get("Code"): window.message_box("Warning", "注册码不正确") sys.exit() else: window.message_box("Warning", "请配置注册码") sys.exit() #window.tray.show()
observersMap[path] = observer def stopSpy(path): observer = observersMap[path] observer.stop() observer.join() del observersMap[path] while 1: sleep(1) drives = getDrives() for i in range(len(drives) - 1, -1, -1): name = GetVolumeInformation(drives[i])[0] if name != '': drives[i] = (drives[i], name) else: del drives[i] if sorted(drives) != allDrives: for dr in drives: if dr not in allDrives: log(dr, 'Added drive:') startSpy(dr[0]) for dr in allDrives: if dr not in drives: log(dr, 'Removed drive:') stopSpy(dr[0]) allDrives = sorted(drives.copy())
def get_volume_label(path): return GetVolumeInformation(path)[0]