国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現獲取磁盤剩余空間的2種方法

2020-01-04 17:17:29
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現獲取磁盤剩余空間的2種方法。分享給大家供大家參考,具體如下:

方法1:

import ctypesimport osimport platformimport sysdef get_free_space_mb(folder):  """ Return folder/drive free space (in bytes)  """  if platform.system() == 'Windows':    free_bytes = ctypes.c_ulonglong(0)    ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(folder), None, None, ctypes.pointer(free_bytes))    return free_bytes.value/1024/1024/1024   else:    st = os.statvfs(folder)    return st.f_bavail * st.f_frsize/1024/1024print(get_free_space_mb('C://'),'GB')

方法2:

import win32com.client as comdef TotalSize(drive):  """ Return the TotalSize of a shared drive [GB]"""  try:    fso = com.Dispatch("Scripting.FileSystemObject")    drv = fso.GetDrive(drive)    return drv.TotalSize/2**30  except:    return 0def FreeSpace(drive):  """ Return the FreeSpace of a shared drive [GB]"""  try:    fso = com.Dispatch("Scripting.FileSystemObject")    drv = fso.GetDrive(drive)    return drv.FreeSpace/2**30  except:    return 0workstations = ['dolphins']print ('Hard drive sizes:')for compName in workstations:  drive = '////' + compName + '//c$'  print ('*************************************************/n')  print (compName)  print ('TotalSize of %s = %f GB' % (drive, TotalSize(drive)))  print ('FreeSpace on %s = %f GB' % (drive, FreeSpace(drive)))  print ('*************************************************/n')

運行效果如下圖:

Python,獲取,磁盤,剩余空間

 

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 澄迈县| 澄江县| 阿克苏市| 穆棱市| 利辛县| 永顺县| 德惠市| 屏东市| 永新县| 仁化县| 梓潼县| 宁波市| 思南县| 太原市| 维西| 北宁市| 上犹县| 开封市| 鹤壁市| 菏泽市| 阆中市| 米易县| 谷城县| 镇康县| 永修县| 吴忠市| 罗定市| 新疆| 弥渡县| 临漳县| 全南县| 汝州市| 辉县市| 安仁县| 喜德县| 遂昌县| 都兰县| 泗阳县| 陆川县| 安溪县| 南雄市|