Python 查找目录下的文件,找出 “.” 开头的隐藏文件并删除 - NOTEBOOK
Python 查找目录下的文件,找出 “.” 开头的隐藏文件并删除
PythonPosted on 2023-05-24
摘要 : 包括自文件夹,层层遍历。
os.path.isdir
startswith
os.remove
import os,shutil
def del_invisiable_file(path='./'):
thisdir = os.listdir(path)
#print(thisdir)
for thisthing in thisdir:
if os.path.isdir(path+thisthing):
#if thisthing.startswith('.'):
# print(path+thisthing)
del_invisiable_file(path+thisthing+'/')
else:
if thisthing.startswith('.'):
print(path+thisthing)
#删除
os.remove(path+thisthing)
del_invisiable_file()