直接上代码,欢迎小伙伴们交流
import os
def getBigFile(path, filesize):
# 遍历指定目录及其子目录
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
target_file = os.path.join(dirpath, filename)
# 判断是否真的是文件
if not os.path.isfile(target_file):
continue
size = os.path.getsize(target_file)
if size > filesize:
size = size//(1024*1024)
size = '{size}M'.format(size=size)
print(target_file, size)
if __name__ == '__main__':
getBigFile('C:\\', 300*1024*1024)