利用os包os.path.walk() 方法递归的遍历路径和文件
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 08 10:29:52 2016
@author: Felix
"""
import os
import sys
def createIfNotExists(path):
if os.path.exists(path):
print "path already exists!"
else:
os.mkdir(path)
print "dir created"
def copy_file(src,tg):
if os.path.exists(tg):
print "path already exists!"
else:
os.system("cp %s %s"%(src,tg))
print "file created"
def check_dirs(src_dir,tg_dir):
for root,dirs,files in os.walk(src_dir):
for d in dirs:
src_dirname=os.path.join(root,d)
tg_dirname=src_dirname.replace(src_dir,tg_dir)
createIfNotExists(tg_dirname)
return True
def copy_all(src_dir,tg_dir):
for root,dirs,files