迭代
python ./demo.py /xx/google/g2/
#coding=UTF-8
import os
import re
import sys
dir='/home/liukaiyi/桌面/py/'
todir='/home/liukaiyi/桌面/test/'
if os.path.isdir(dir)==False:
os.mkdir(dir)
if os.path.isdir(todir)==False:
os.mkdir(todir)
usedir=sys.argv[1]
dir+=usedir+'/'
todir+=usedir+'/'
mk_dir = '/'
for tdir in dir.split('/'):
if tdir=="":
continue
mk_dir += tdir+'/'
if os.path.isdir(mk_dir)==False:
os.mkdir(mk_dir)
mk_todir = '/'
for tdir in todir.split('/'):
if tdir=="":
continue
mk_todir += tdir+"/"
if os.path.isdir(mk_todir)==False:
os.mkdir(mk_todir)
def action(path,tpath,file):
print '>>>>>>>>>>>>>>'+path,tpath,file
def listAll(rootpath):
tpath = todir+re.sub(dir,"",rootpath)
if os.path.isdir(tpath)==False:
os.mkdir(tpath)
print 'mkdir>'+tpath
for file in os.listdir(rootpath):
if os.path.isfile(rootpath+file):
filename = ".".join(file.split('.')[0:-1])
bool = False
for tfile in os.listdir(tpath) :
if ".".join(tfile.split('.')[0:-1]) == filename :
bool=True
if bool==False:
action(rootpath,tpath,file)
for file in os.listdir(rootpath):
path = rootpath+file+'/'
if os.path.isdir(path):
listAll(path)
listAll(dir)
整理 www.blogjava.net/Good-Game