在一个数据集中有1.png
和1_1.png
,这是一个pair对
,现在不想要带有下划线的图片了,下面程序可以批量删除带有_
字符的图片
import os
path = "C:\\Users\\Administrator\\Desktop\\testB" # 文件路径
a = 1
for file in os.listdir(path):
b = os.path.join(path, file)
if os.path.isfile(os.path.join(path, file))==True:
if file.find('_') is not -1:
os.remove(os.path.join(path, file))
print(file, "ok")
a = a+1