I want to automate my folder creation using python, the desired hierarchy as picture below,
I created list of the first hierarchy
A.1 = [
'A.1', 'A.2'
]
A.2 = [
'A2.1'
]
This is the main code that i run to automate the folder creation, but i managed to automate it until 2nd hierarchy (A.1.1, A.1.2).
import os
main_dir = [A.1, A.2] # Loading the list of sub-directories
root_dir = 'A'
main_dir_names = ['A.1', 'A.2'] # Name of the sub-directories
def main():
# Create directory
for i in range(0, len(main_dir)):
for j in range(0,len(main_dir[i])):
dirName = str(root_dir) + '/' + str(main_dir_names[i]) +'/' + str(main_dir[i][j])
try:
# Create target Directory
os.makedirs(dirName)
print("Directory " , dirName , " Created ")
except FileExistsError:
print("Directory " , dirName , " already exists")
# Create target Directory if don't exist
if not os.path.exists(dirName):
os.makedirs(dirName)
print("Directory " , dirName , " Created ")
else:
print("Directory " , dirName , " already exists")
if __name__ == '__main__':
main()
Do you guys have any idea how can i automate my code so i can automate folder creation until 3rd hierarchy (A.1.2.1)?