效果如下:
代码:
import os
class ReadImageName():
def __init__(self):
self.path = '.'
def readname(self):
filenames = os.listdir(self.path)
flielist = []
for item in filenames:
if item.endswith('.jpg'):
itemname = os.path.join(self.path, item)
itemname = itemname[-11:]
flielist.append(itemname)
fo = open("imagename.txt", "w")
for item in flielist:
fo.write(str(item) + "\n")
if __name__ == '__main__':
log = ReadImageName()
log.readname()