将一个文件夹中的所有图片移到另外一个文件夹中,包含二级文件夹中的

# coding=utf-8
import os
import shutil

#目标文件夹,此处为相对路径,也可以改为绝对路径
determination = '/Users/huhao/Downloads/test'
if not os.path.exists(determination):
    os.makedirs(determination)

#源文件夹路径
path = '/Users/huhao/Downloads/ClusterLabel_STORE_general_general_20210428_product_storeinone_bigthan50_splitby50'
folders = os.listdir(path)

for folder in folders:
    dir = path + '/' + str(folder)+ '/' +str(folder)#二级文件夹
    files = os.listdir(dir)
    for file in files:
        source = dir + '/' + str(file)
        deter = determination + '/' + str(file)
        shutil.copyfile(source, deter)

 

转载https://blog.csdn.net/Rocky6688/article/details/107341334/,非原创

    原文作者:这个利弗莫尔不太冷
    原文地址: https://blog.csdn.net/weixin_48262500/article/details/116482368
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞