【发布时间】:2017-05-05 05:53:32
【问题描述】:
我正在尝试删除文件夹中的一些档案。
这是我为此写的:
import sys
import os
from os import listdir
from os.path import join
dir_path = os.path.dirname(os.path.realpath(__file__))
for file in dir_path:
if (file.endswith(".gz")) or (file.endswith(".bz2")):
os.remove(join((dir_path), file))
print("Removed file.")
print("Done.")
当我运行模块时,它只会打印“完成”。但不删除任何文件,即使在与模块相同的目录中有具有该扩展名的文件。
不知道我做错了什么,帮忙?
【问题讨论】:
标签: python file python-3.x operating-system delete-file