#删除指定路径下的指定文件
#先导入所需的包
import os
#指定路径
path = '/home/xxx/xxx/'
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(".txt"): # 需要 被删除文件的后缀名
os.remove(os.path.join(root, name))
print("Delete File: " + os.path.join(root, name))
利用python删除服务器中指定文件夹内的指定后缀名文件代码如下#删除制定路径下的指定文件#先导入所需的包import os#指定路径path = '/home/xxx/xxx/'for root, dirs, files in os.walk(path): for name in files: if name.endswith(".txt"): # 需要 被删除文件的后缀名 os.remove(os.path.