程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

python将文件从一个文件夹复制到另一个文件夹中,路径的输入用“C:/a/”可以,用"C:\a\"不可以

发布于2019-09-06 12:26     阅读(1648)     评论(0)     点赞(16)     收藏(5)


import easygui
from shutil import copy
import os
import re
dest_dir = input('Please enter destination path:(split path with "\\")')
source_dir = input('Please enter source path:(split path with "\\")')
j=0
if not dest_dir.endswith("/"):
    dest_dir += '/'
if not source_dir.endswith('/'):
    source_dir += '/'
if os.path.isdir(dest_dir) and os.path.isdir(source_dir):
    for root, dirs, files in os.walk(source_dir):
        for i in range (0, files.__len__()):
            sf = os.path.join(root, files[i])
            dst = re.sub('([A-Za-z]:/.*?)/', dest_dir, root)
            if not os.path.exists(dst):
                os.makedirs(dst)
            copy(sf, dst)
            j += 1
    print ('Done!')
   
    print (j)
   
else:
    raise Exception('Wrong path entered!')
 
input()

 



所属网站分类: 技术文章 > 博客

作者:丸子

链接:https://www.pythonheidong.com/blog/article/98603/b1c3f7d71decbbefd3cc/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

16 0
收藏该文
已收藏

评论内容:(最多支持255个字符)