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

首頁 > 編程 > Python > 正文

Python實現(xiàn)獲取磁盤剩余空間的2種方法

2019-11-25 16:07:08
字體:
來源:轉載
供稿:網(wǎng)友

本文實例講述了Python實現(xiàn)獲取磁盤剩余空間的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相關內(nèi)容感興趣的讀者可查看本站專題:《Python編碼操作技巧總結》、《Python數(shù)據(jù)結構與算法教程》、《Python Socket編程技巧總結》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 石门县| 上犹县| 西吉县| 威宁| 襄汾县| 原阳县| 延寿县| 昌黎县| 上饶县| 尉氏县| 饶平县| 东乡族自治县| 达州市| 仁寿县| 曲松县| 阿拉尔市| 新丰县| 白山市| 泽库县| 宕昌县| 福建省| 墨脱县| 无极县| 三原县| 丁青县| 共和县| 扶风县| 富源县| 屯昌县| 修文县| 晴隆县| 崇义县| 宜兰县| 南漳县| 龙游县| 晋中市| 保康县| 吉林省| 防城港市| 伊宁县| 九龙城区|