通过输入目录地址,可查找指定目录下的大文件。脚本如下:
# -*- coding: utf-8 -*-
# @CreateTime : 2022/2/15 14:25
# @ModifyTime : 2022/2/15 14:25
# @Author : xuming
# @File : get_big_file.py
# @Software: PyCharm
# @Description:
import os
def get_big_file(path, file_size):
"""
@param path: 目录绝对路径
@param file_size: 文件大小,单位Mb
@return: 文件名称及大小
"""
all_files = []
res = os.walk(path)
for root, dirs, files in res:
if files:
for i in files:
file = os.path.join(root, i)
size_m = os.path.getsize(file) / 1024 / 1024
if size_m > file_size:
all_files.append((file, size_m))
return all_files