os.stat没有给我正确的输出,每个文件我只得到8192字节。以下是代码:
import os
path = "C:\\"
filelist = os.listdir(path)
for i in filelist:
if os.path.isdir(os.path.join(path, i)):
print os.path.join(path, i), "is DIR"
else:
# fs = filesize
fs = os.stat(path).st_size
# fs = os.path.getsize(path)
print os.path.join(path, i), "size is", fs
下面是输出结果:
C:\$Recycle.Bin is DIR
C:\Config.Msi is DIR
C:\Documents and Settings is DIR
C:\hiberfil.sys size is 8192
C:\pagefile.sys size is 8192
C:\PerfLogs is DIR
C:\Program Files is DIR
C:\Program Files (x86) is DIR
C:\ProgramData is DIR
C:\Python27 is DIR
C:\Recovery is DIR
C:\shared.log size is 8192
C:\System Volume Information is DIR
C:\Users is DIR
C:\vcredist_x86.log size is 8192
C:\Windows is DIR
为什么最大的数字是8192?所有非目录文件的大小都比它大得多。 os.stat(path).st_size和os.path.getsize(path)的输出相同。提前致谢。
os.stat(path)
!=os.stat(os.path.join(path, i))
- Łukasz Rogalski