转移图片位置

import glob
import os,sys
import shutil




fileDir = 'F:/project/Breast/InBreast/INBreast/outimgpatch/calcification/'
fileDir1 = 'F:/project/Breast/InBreast/INBreast/outimgpatch/nocalcification/'    #移动到新的文件夹路径
fileDir2 = 'F:/project/Breast/InBreast/INBreast/outtxtpatch/'    #移动到新的文件夹路径
tarDir = 'F:/project/Breast/InBreast/INBreast/outimgpatch/allcalcification/'    #源图片文件夹路径
tarDir1 = 'F:/project/Breast/InBreast/INBreast/outimgpatch/allnocalcification/'    #源图片文件夹路径
tarDir2 = 'F:/project/Breast/InBreast/INBreast/outimgpatch/allouttxtpatch/'    #源图片文件夹路径
import os, random, shutil


if __name__ == '__main__':
    txtLists = os.listdir(fileDir)  # 列出文件夹下所有的目录与文件
    for filename in txtLists:
        print(filename)
        source = fileDir + filename + '/'
        source1 = fileDir1 + filename + '/'
        source2 = fileDir2 + filename + '/'
        pathDir = os.listdir(source)  # 取图片的原始路径
        for name in pathDir:
                shutil.copy(source + name, tarDir + name)
                shutil.copy(source1 + name, tarDir1 + name)
                shutil.copy(source2 + name[:-4] + '.txt', tarDir2 + name[:-4] + '.txt')
原文地址:https://www.cnblogs.com/ziytong/p/11213616.html