import os
laspth='D:/toWuda/lidardata/'
data = []
i=1
for line in open("D:/toWuda/name.txt", "r"): # 设置文件对象并读取每一行文件
line=line.strip('\n')
data.append(line)
for las in os.listdir(laspth):
file_name=laspth + las
if las not in data:
os.remove(file_name)
print('成功删除文件:', file_name)
else:
print(str(i)+' 文件存在: '+las)
i+=1
print('fns')
Read the file name in txt, delete the file that is not in txt
Guess you like
Origin blog.csdn.net/weixin_61235989/article/details/129880828
Recommended
Ranking