# -*- coding: utf-8 -*-
import os
import shutil
# 读取文件的路径
read_path = r"E:\0\JPG/"
# 存放文件的路径
save_path = r"E:\0\0jpg/"
if not os.path.exists(save_path):
os.mkdir(save_path)
fileType = '.jpg' #文件后缀按需修改(.xml,.txt等都可以)
num = 0
# 读取并遍历读取txt中的每行
with open('E:/A.txt', 'r') as f:
for name in f:
fileName = name.strip() # 去除末尾的换行
# print(fileName)
# print(type(fileName)) # 查看文件类型
# 读取并遍历文件夹中的图片
for file in os.listdir(read_path):
# print(file)
# print(type(file))
if fileName + fileType == file:
num += 1
#move移动剪切,可以改成copy复制 按需修改
shutil.move(os.path.join(read_path, fileName + fileType), save_path)
print("%s Move successfully" % (fileName + fileType))
print("Move complete!")
print("Total pictures copied:", num)