"disk_usage" 从 shutil 库返回的字节与目录文件大小不匹配
Bytes returned by "disk_usage" from the shutil library doesn't match the directory file size
我在Python网站上阅读shutil的官方文档,然后我运行一个disk_usage 测试,但它没有返回我所期望的,在该目录(文件夹)中有一个 669 kb 的文件。
这是代码:
import os
import shutil
os.chdir(r"D:\python\topics\shutil\disk_usage")
directory = "test_folder"
total, used, free = shutil.disk_usage(directory)
print(used)
输出:
177422868480 (which I suppose is the value in bytes)
预期输出:
669000 (since the file inside is 669 kb)
为什么我没有得到预期的输出?
谢谢
shutil.disk_usage()
returns 整个磁盘(文件系统、卷)的统计信息,而不仅仅是您传入的特定目录。
要计算一个目录及其子目录使用的磁盘 space,请参阅:Calculating a directory's size using Python?
有关一些潜在陷阱的详细介绍,请参阅:https://blogs.msdn.microsoft.com/oldnewthing/20041228-00/?p=36863
我在Python网站上阅读shutil的官方文档,然后我运行一个disk_usage 测试,但它没有返回我所期望的,在该目录(文件夹)中有一个 669 kb 的文件。
这是代码:
import os
import shutil
os.chdir(r"D:\python\topics\shutil\disk_usage")
directory = "test_folder"
total, used, free = shutil.disk_usage(directory)
print(used)
输出:
177422868480 (which I suppose is the value in bytes)
预期输出:
669000 (since the file inside is 669 kb)
为什么我没有得到预期的输出?
谢谢
shutil.disk_usage()
returns 整个磁盘(文件系统、卷)的统计信息,而不仅仅是您传入的特定目录。
要计算一个目录及其子目录使用的磁盘 space,请参阅:Calculating a directory's size using Python?
有关一些潜在陷阱的详细介绍,请参阅:https://blogs.msdn.microsoft.com/oldnewthing/20041228-00/?p=36863