问题遇到的现象和发生背景
要求计算出source目录里面(不包含子目录)所有的文件的大小之和。
问题相关代码,请勿粘贴截图
import os
from os.path import isfile, join
targetDir = 'C:\source'
totalsize = 0
for f in os.listdir(targetDir):
filePath = join(targetDir, f)
if isfile(filePath):
totalsize += os.path.getsize(filePath)
print(f'合计大小为 {totalsize} 字节')
运行结果及报错内容
这是他的运行结果,但是我查看文件夹属性发现他有9000多字节
为什么会少?