python删除指定文件夹下小于100k的文件
例:代码保存为del100k.py
import os def get_path(file_path): for root, dirs, files in os.walk(file_path): for file in files: filename = os.path.join(root, file) del_file(filename) def del_file(filename): size = os.path.getsize(filename) if size < 100 * 1024: print("remove", filename) os.remove(filename) if __name__ == "__main__": file_path = "C:\Windows\Web\gallery" get_path(file_path)
运行:
#sudo python ./home/xlpc/del100k.py