今天在整理电脑文件时,发现f盘中的一个文件夹里有很多重复的rar格式的压缩文件。手动删除太费力,就搞个python程序自动> 删除一哈。
import os def del_files(path): for root, dirs, files, in os.walk(path): for name in files: if name.endswith(".rar"): os.remove(os.path.join(root, name)) print("Delete file:" + os.path.join(root, name)) if __name__ == "__main__": path="文件路径" del_files(path)