def get_bytes(path): """ 获取指定位置回收站内总文件大小 :param path: 回收站的路径。可以是驱动器,文件夹 or None. None 就是查询所有的回收站 :return: 回收站内总文件大小 """ (bytes_used, num_files) = shell.SHQueryRecycleBin(path) return bytes_used
def is_empty(path): """ 检查指定位置的回收站是否为空 :param path: 回收站的路径。可以是驱动器,文件夹 or None. None 就是查询所有的回收站 :return: """ (bytes_used, num_files) = shell.SHQueryRecycleBin(path) return num_files == 0
def empty_recycle_bin(drive, really_delete): """Empty the recycle bin or preview its size""" bytes_used = shell.SHQueryRecycleBin(drive)[0] if really_delete and bytes_used > 0: # Trying to delete an empty Recycle Bin on Vista/7 causes a # 'catastrophic failure' flags = shellcon.SHERB_NOSOUND | shellcon.SHERB_NOCONFIRMATION | shellcon.SHERB_NOPROGRESSUI shell.SHEmptyRecycleBin(None, drive, flags) return bytes_used
def empty_recycle_bin(path, really_delete): """Empty the recycle bin or preview its size. If the recycle bin is empty, it is not emptied again to avoid an error. Keyword arguments: path -- A drive, folder or None. None refers to all recycle bins. really_delete -- If True, then delete. If False, then just preview. """ (bytes_used, num_files) = shell.SHQueryRecycleBin(path) if really_delete and num_files > 0: # Trying to delete an empty Recycle Bin on Vista/7 causes a # 'catastrophic failure' flags = shellcon.SHERB_NOSOUND | shellcon.SHERB_NOCONFIRMATION | shellcon.SHERB_NOPROGRESSUI shell.SHEmptyRecycleBin(None, path, flags) return bytes_used
def getTotalSizeInRecyclerBin(self, raw=False): cadena = '' B = shell.SHQueryRecycleBin()[0] Gb = B / 1073741824 Mb = B / 1048576 Kb = B / 1024 B = B % 1024 if raw: return {'GB':int(Gb),'MB':int(Mb)%1024,'KB':int(Kb)%1024,'B':B} else: if Gb > 1: cadena = '{:.3f} Gb'.format(Gb) elif Mb > 1: cadena = '{:.3f} Mb'.format(Mb) elif Kb > 1: cadena = '{:.3f} Kb'.format(Kb) else: cadena = '{} bytes'.format(B) return cadena
def _get_recycle_bins(): #logging.debug(repr(win32api.GetLogicalDrives())) drives = win32api.GetLogicalDriveStrings() #logging.debug(repr(drives.split("\0"))) bin_info = [] for drive in drives.split("\0"): drive_type = win32file.GetDriveType(drive) if drive_type in (win32file.DRIVE_FIXED, win32file.DRIVE_RAMDISK #win32file.DRIVE_REMOVABLE ): # Detect SUBSTed volume and ignore it try: volume_mapping = win32file.QueryDosDevice(drive[:2]) if volume_mapping.startswith("\\??\\"): break except: pass try: size, files = shell.SHQueryRecycleBin(drive) bin_info.append((drive, size, files)) logging.debug(drive + str(drive_type)) except Exception, e: log.error(e)
def getNumItemsInRecyclerBin(self): return shell.SHQueryRecycleBin()[1] def getProcessID(self, nameprocess):
def get_size(self): size, _ = shell.SHQueryRecycleBin(None) return size
def __len__(self): _, n_items = shell.SHQueryRecycleBin(None) return n_items