I'm trying to write a nested while loop that will create n number of folders with n number of sub-directories. The problem with my current code is that the first folder created does not contain the sub-directories. Only the 2nd directory made contains the sub-directories. My goal is to write a program that runs a parametric sweep with groundwater modeling software, and I need these directories to save the results.
import subprocess, os
i = 1
j = 1
while i <= 2:
path = r'C:/Users/TEvans/Desktop/Testing/slope%d' % i
if not os.path.exists(path): os.makedirs(path)
os.chdir(path)
i = i+1
while j <= 3:
path1 = r'C:/Users/TEvans/Desktop/Testing/slope%d/r%d' % (i, j)
if not os.path.exists(path1): os.makedirs(path1)
j = j+1
os.chdir(path)is not required. Theos.makedirs(path)in the outer loop is not required. The call toos.makedirs(path1)in the inner loop will create theslope%ddirectory if it does not exist.