python3将某个目录的所有子目录中的文件拷贝到另一个目录下
程序员文章站
2022-06-16 12:34:07
...
# -*- 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)