pytho获取磁盘剩余空间

需安装后Python for Windows Extensions

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

    if path is None:
        if os.name == 'nt':
            path = "C:\\"
        else:
            path = '/'
    if os.name == 'nt':
        import win32file
        res_list = win32file.GetDiskFreeSpace(path)
        disk_free_space = res_list[0]*res_list[1]*res_list[2]/(1024*1024.0)
    else:
        import statvfs
        vfs = os.statvfs(path)
        disk_free_space = vfs[statvfs.F_BAVAIL]*vfs[statvfs.F_BSIZE]/(1024*1024.0)



你可能感兴趣的:(python)