python實現從某一文件夾子文件夾的所有文件拷貝到新文件夾中

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import os
import shutil

src_path = "D:\python\standardtopo_withfolder"
dst_path = "D:\python\standardtopo_withoutfolder"

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)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章