python3将某个目录的所有子目录中的文件拷贝到另一个目录下

# -*- coding:utf-8 -*-

import os
import shutil

src_path = "F:\\test1"
dst_path = "F:\\test2"

def mycopy(srcpath, dstpath):
    if not os.path.exists(srcpath):
        print("srcpath not exist!")
    if not os.path.exists(dstpath):
        print("dstpath not exist!")
    for root, dirs, files in os.walk(srcpath, True):
        for eachfile in files:
            shutil.copy(os.path.join(root, eachfile), dstpath)

if __name__ == "__main__":
    mycopy(src_path, dst_path)


版权声明:本文为yldmkx原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。