Find free disk space in python on OS/X

后端 未结 7 1158
死守一世寂寞
死守一世寂寞 2020-12-08 07:51

I\'m looking for the number of free bytes on my HD, but have trouble doing so on python.

I\'ve tried the following:

import os

stat = os.statvfs(path         


        
7条回答
  •  萌比男神i
    2020-12-08 08:23

    def FreeSpace(drive):
        """ Return the FreeSape of a shared drive in bytes"""
        try:
            fso = com.Dispatch("Scripting.FileSystemObject")
            drv = fso.GetDrive(drive)
            return drv.FreeSpace
        except:
            return 0
    

提交回复
热议问题