import os
path = 'F:/datasets/ship/coco/val2017'
f = 'F:/datasets/ship/coco/test.txt'
# 将文件夹下的文件名存放到txt文件中
def read_writeFile(path, f):
cate = [path + '/' + x for x in os.listdir(path)]
f2 = open(f, 'a+')
for idx, folder in enumerate(cate):
folder = folder.split('/')[-1][:-4]
print(folder)
f2.write(folder+ '\n')
read_writeFile(path, f)