Python—批量复制文件

版权声明:本文为作者的原创文章,转载请注明出处。 https://blog.csdn.net/u014421797/article/details/83243185

批量复制文件,并修改后缀名 


import os,shutil
  
#yml文件根路径
ymlroot = 'E:\\GTEA_gaze\\'    
# 原始图片根路径
srcroot='E:\\GTEA_Gaze_Dataset\\png\\'
# 目标图片根路径
dstroot='E:\\Gaze\\'
for i in range(22):
    j = "%03d" % i
    ymlpath = ymlroot + str(j)  #依次去提取001,002,...文件夹下的文件
    srcpath = srcroot + str(j)
    dstpath = dstroot + str(j)
    L = file_name(ymlpath)     #批量提取文件的函数
    for k in L:
        # 找对应的图片
        src=os.path.join(os.path.abspath(srcpath),k+'.png')
        # 重命名,改为jpg格式
        dst=os.path.join(os.path.abspath(dstpath),k+'.jpg')
        # 执行操作,复制文件
        shutil.copyfile(src,dst)

file_name函数地址:https://blog.csdn.net/u014421797/article/details/83243042

猜你喜欢

转载自blog.csdn.net/u014421797/article/details/83243185