0
다른 파일 (파일 목록에 따라 일부 파일 만 이동) 입력 - 테스트 파일/폴더 구조의 생성을 자동화하는 스크립트를 작성하고 있습니다. 내 코드는 아래 작동하지만 동일한 작업을 완료하는 데 더 무한한 방법이 있습니까?python 재귀 폴더 구조 만들기
import os
import shutil
os.chdir('c:/')
if not os.path.exists('c:/pythontest'):
os.mkdir('c:/pythontest')
else:
shutil.rmtree('c:/pythontest')
os.mkdir('c:\pythontest')
os.chdir('c:/pythontest')
for i in range(0,3):
os.mkdir('folder%d' % i)
fileName = 'folder%d' % i
filePath = os.path.join(os.curdir, fileName)
print filePath
os.chdir(filePath)
for j in range(0,3):
os.mkdir('folder%d_%d' % (i,j))
fileName = 'folder%d_%d' % (i,j)
filePath = os.path.join(os.curdir, fileName)
print str(filePath)
os.chdir(filePath)
for k in range(0,3):
try:
f = open('file%d_%d_%d.txt' % (i,j,k), 'w')
except IOError:
pass
os.chdir('..')
os.chdir('..')