请教一下大神如何用python读取图片的txt标签内容并将图片及对应标签移动至指定文件夹

2024-11-18 03:32:21
推荐回答(1个)
回答(1):

import os
def search(s, path=os.path.abspath('.')):
for z in os.listdir(path):
if os.path.isdir(path + os.path.sep + z):
print('Currnet:', path)
path2 = os.path.join(path, z)
print('future:', path2)
search(s, path2)
elif os.path.isfile(path + os.path.sep + z):
if s in z:
print(os.path.join(path, z))
with open(path + os.path.sep + z, 'r') as fr:
with open('save.txt', 'a') as fw:
fw.write(path + '\t' + fr.read())
search('csv', '.')