# -*- coding: gb2312 -*-
# 创建递归目录
import os
import random
import time
#===============================================================================================================
# 常量
#===============================================================================================================
isDebug = 0
identifyCode = "kWs2zMxSct3"
deepNumber = 3
randomBegin = 1000000
randomEnd = 2000000
debugNum = 0
#===============================================================================================================
# 功能函数
#===============================================================================================================
# 创建初始目录
def createInitFolder():
initFolder = time.strftime(r"%Y-%m-%d_%H-%M-%S", time.localtime())
initFolder = "%s-%s-%s" % (identifyCode, initFolder, random.randint(randomBegin, randomEnd))
initFolder = "%s/%s" % (os.getcwd(), initFolder)
os.makedirs(r'%s'% (initFolder))
return initFolder
# CREATE FOLDER IN NUMBER
def createFolderInNumber(rootFolder, deepNum):
global debugNum
for i in range(deepNum):
if 0 == debugNum:
folder = "%s" % random.randint(randomBegin, randomEnd)
else:
folder = "%s" % debugNum
debugNum += 1
os.makedirs(r'%s/%s' % (rootFolder, folder))
# 递归创建目录
def loop(initFolder, deepNum, passNumber):
if 0 > passNumber:
return
# 按照数量创建目录
createFolderInNumber(initFolder, deepNum)
L = os.listdir(initFolder)
if 1 == isDebug: print L
for i in range(len(L)):
createFolder = "%s/%s" % (initFolder, L[i])
if 1 == isDebug: print createFolder
os.chdir(createFolder)
loop(createFolder, len(L), passNumber - 1)
#===============================================================================================================
# 逻辑部分
#===============================================================================================================
if "__main__" == __name__:
# 创建初始目录
initFolder = createInitFolder()
# 递归创建目录
loop(initFolder, deepNumber, deepNumber - 1)
# 创建结束
if 1 == isDebug:
print "CREATE END debugNum is ", debugNum
else:
print "CREATE END "