python 拷贝指定文件到另一个文件夹

import os
import shutil

filelist = []

txtpath = "E:\\数据集备份\\11111\\0414\\11111\\labels"
imgpath = "E:\\数据集备份\\11111\\0414\\11111\\JPEGImages"
for home, dirs, files in os.walk(txtpath):
    for filename in files:
        print(filename.split(".")[0])
        filelist.append(filename.split(".")[0])

for file in filelist:
    print("开始拷贝")
    originaltxtpath = txtpath+"\\"+ file + ".txt"
    originalimgpath = imgpath+"\\" + file + ".jpg"
    desimgpath = "C:\\pytorch_object_detection\\datasets\\img\\"+ file + ".jpg"
    deslabelpath = "C:\\pytorch_object_detection\\datasets\\label\\" + file + ".txt"
    shutil.copyfile(originalimgpath, desimgpath)
    shutil.copyfile(originaltxtpath, deslabelpath)
    print("拷贝结束")

Supongo que te gusta

Origin blog.csdn.net/sxmsxmsmxm/article/details/130155316
Recomendado
Clasificación