#!/usr/bin/env python
import time
import os
import shutil
filelist=[]
rootdir="E:/mm618"
filelist=os.listdir(rootdir)
for f in filelist:
filepath = os.path.join( rootdir, f )
if os.path.isfile(filepath):
os.remove(filepath)
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))+"->"+filepath+" removed!")
elif os.path.isdir(filepath):
shutil.rmtree(filepath,True)
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))+"->"+"dir "+filepath+" removed!")
Python | 删除指定文件下的所有文件和文件夹
最新推荐文章于 2024-04-22 11:13:10 发布