python - os.path.getsize 在 Windows 10 中给出错误的 .dll 文件大小

标签 python file windows-10

Python 3.6.0、Windows 10(64 位)

import os
path = r'C:\Windows\System32\AdvancedInstallers\cmiv2.dll'
print(os.path.getsize(path))

这段代码给出了 2193248 的输出,但是当我看到这个文件的属性时,它显示了 3252576。它不是磁盘属性的大小。我说的是实际尺寸。

file properties

我期待 python 程序打印 3252576

最佳答案

可能与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)。

关于python - os.path.getsize 在 Windows 10 中给出错误的 .dll 文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42335950/

相关文章:

python - Pandas : Getting indexes of a series providing multiple filters

python - 自动在python中创建多个文件夹

dll - 处理 LoadLibrary 失败,错误 1114

python - Python中每个句子的首字母大写

python - 检查列表中的子列表

python - 从 SQLAlchemy InstrumentedAttribute 中提取一个 weekday() (列类型是 datetime)

javascript - 从另一个 JavaScript 编写一个 JavaScript 文件

php - jQuery.ajax 文件删除

Windows 10 : Error code 52 in device manager with correct signature in cross-signed driver

windows-10 - Windows Phone 8.1 silverlight 应用程序可以在 Windows 10 Phone 上运行吗?