例:代码保存为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:WindowsWebgallery" 17 get_path(file_path)
运行:
#sudo python ./home/xlpc/del100k.py