pytho获取磁盘剩余空间

水深无声 2022-08-02 12:45 309阅读 0赞

需安装后Python for Windows Extensions

http://sourceforge.net/projects/pywin32/files/pywin32/

  1. if path is None:
  2. if os.name == 'nt':
  3. path = "C:\\"
  4. else:
  5. path = '/'
  6. if os.name == 'nt':
  7. import win32file
  8. res_list = win32file.GetDiskFreeSpace(path)
  9. disk_free_space = res_list[0]*res_list[1]*res_list[2]/(1024*1024.0)
  10. else:
  11. import statvfs
  12. vfs = os.statvfs(path)
  13. disk_free_space = vfs[statvfs.F_BAVAIL]*vfs[statvfs.F_BSIZE]/(1024*1024.0)

发表评论

表情:
评论列表 (有 0 条评论,309人围观)

还没有评论,来说两句吧...

相关阅读