Last active
November 14, 2017 04:15
-
-
Save youqingkui/cd6d704e9787435df2e5 to your computer and use it in GitHub Desktop.
使用Python查看磁盘大小信息
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def disk_stat(folder): | |
""" | |
查看文件夹占用磁盘信息 | |
:param folder: 文件夹路径 | |
:return: | |
""" | |
hd={} | |
disk = os.statvfs(folder) | |
print(disk) | |
# 剩余 | |
hd['free'] = disk.f_bavail * disk.f_frsize | |
# 总共 | |
hd['total'] = disk.f_blocks * disk.f_frsize | |
# 已使用 | |
hd['used'] = hd['total'] - hd['free'] | |
# 使用比例 | |
hd['used_proportion'] = float(hd['used']) / float(hd['total']) | |
return hd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment