Python 3.6.0,Windows 10(64位)
import os
path = r'C:\Windows\System32\AdvancedInstallers\cmiv2.dll'
print(os.path.getsize(path))
此代码提供2193248
的输出,但是当我看到此文件的属性时,它会显示3252576
。它不是磁盘属性的大小。我说的是实际尺寸。
我期待python程序打印3252576
。
答案 0 :(得分:1)
这可能与NTFS alternate data streams有关。虽然文章指出ADS在文件中的存在不会影响其大小,但自从撰写文章(早在2004年)以来,事情可能已经发生了变化,而Windows 10的属性对话框可能很好地解释了文件中的所有ADS,而python没有。
A more recent blog post解释了如何使用PowerShell实用程序检查文件的数据流:
Get-item -Path C:\Windows\System32\AdvancedInstallers\cmiv2.dll -stream *
如果我的假设是正确的,那么输出应该如下所示:
FileName: C:\Windows\System32\AdvancedInstallers\cmiv2.dll
Stream Length
------ ------
:$DATA 2193248
SomethingElse 1059328
(或 SomethingElse 实际上可能包含几个较小的流,大小最多为1059328)。