首页 > 编程语言 > 详细

递归算法,递归复制目录

时间:2020-03-12 18:00:24      阅读:61      评论:0      收藏:0      [点我收藏+]
import os
import shutil
# todo python 递归算法


def copy(src,dest):
    files=os.listdir(src)
    os.mkdir(dest)
    for file in files:
        src_file_path= os.path.join(src,file)
        dest_file_path=os.path.join(dest,file)
        if os.path.isfile(src_file_path):
            with open(src_file_path,"rb")as rs:
                reader_stream=rs.read()
            with open(dest_file_path,"wb")as ws:
                ws.write(reader_stream)
        else:
            # is dir
            copy(src_file_path,dest_file_path)

  

方法2:

使用shutil 

#赋值文件以及空目录

shutil.copyfile(src,dest)

# 递归复制目录以及目录文件

shutil.copytree(src,dest)

递归算法,递归复制目录

原文:https://www.cnblogs.com/SunshineKimi/p/12470106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!