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)

相关文章:

  • 2021-04-29
  • 2021-10-13
猜你喜欢
  • 2021-09-23
  • 2021-07-23
  • 2022-01-27
  • 2022-12-23
  • 2021-12-19
  • 2021-10-16
相关资源
相似解决方案