例:代码保存为del100k.py
1 import os 2 3 def get_path(file_path): 4 for root, dirs, files in os.walk(file_path): 5 for file in files: 6 filename = os.path.join(root, file) 7 del_file(filename) 8 9 def del_file(filename): 10 size = os.path.getsize(filename) 11 if size < 100 * 1024: 12 print("remove", filename) 13 os.remove(filename) 14 15 if __name__ == "__main__": 16 file_path = "C:\Windows\Web\gallery" 17 get_path(file_path)
运行:
#sudo python ./home/xlpc/del100k.py
原文地址:https://www.cnblogs.com/xlpc/p/12356372.html
时间: 2024-10-11 04:55:40