阅读背景:

Python递归拷贝文件夹下所有目录和文件_学习日常_python拷贝文件夹目录和文件

来源:互联网 

定义函数如下:

def copydirs(from_file, to_file):
    if not os.path.exists(to_file):  # 如不存在目标目录则创建
        os.makedirs(to_file)
    files = os.listdir(from_file)  # 获取文件夹中文件和目录列表
    for f in files:
        if os.path.isdir(from_file + '/' + f):  # 判断是否是文件夹
            copydirs(from_file + '/' + f, to_file + '/' + f)  # 递归调用本函数
        else:
            shutil.copy(from_file + '/' + f, to_file + '/' + f)  # 拷贝文件def copydirs(from_file, to_file):
   



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: