import os
class ReadImageName():
def __init__(self):
self.path = r'\Annotations'#图片地址
def readname(self):
filenames = os.listdir(self.path)
flielist = []
for item in filenames:
if item.endswith('.png'):
# itemname = os.path.join(self.path, item)
itemname = item[:-4]
flielist.append(itemname)
fo = open(r"E:\name.txt", "w")#txt地址
for item in flielist:
fo.write(str(item) + "\n")
if __name__ == '__main__':
log = ReadImageName()
log.readname()
06-28
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-09
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-12