Python_使用Python将一个文件夹下的多个文件夹中的图片复制到一个文件夹中

 

代码:

复制代码
# coding=utf-8
import os
import shutil

#目标文件夹(最终要复制到的文件夹),此处为相对路径,也可以改为绝对路径
determination = '/../../目标文件夹/'
if not os.path.exists(determination):
    os.makedirs(determination)

#源文件夹路径
path = '/../../源文件夹'
folders = os.listdir(path)
for folder in folders:
    dir = path + '/' + str(folder)
    files = os.listdir(dir)
    for file in files:
        source = dir + '/' + str(file)
        deter = determination + '/' + str(file)
        shutil.copyfile(source, deter)
复制代码

路径设置为绝对路径的话直接运行py文件就可以了,如果为相对路径注意文件路径。

本文作者:seven&night

本文链接:https://www.cnblogs.com/bisiyuan/p/16943841.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   seven&night  阅读(635)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 晴天 刘瑞琦
晴天 - 刘瑞琦
00:00 / 00:00
An audio error has occurred.