I want to create folder and subfolder in an a specific directory by writing code in python.
It is important to check directory and folder if exist a specific subfolder, avoid duplicate or overwrite.
I create a loop but when directory or folder is empty it does not go to the loop or it gives me error.
I don't know how can create my folders.
Part of my code is like this:
# Set workspace env.workspace = r"..\..\Test" # Set local variables main_folder_path = r"..\..\Test" main_foldNam1 = "OutPutSpace" # Execute CreateFolder folders = os.listdir(main_folder_path) for folder in folders: # if os.path.isdir(os.path.join(main_folder_path, main_foldNam1)) == True: if arcpy.Exists(main_foldNam1): print main_foldNam1, "folder is Exist", "\n" else: arcpy.CreateFolder_management(main_folder_path, main_foldNam1) gdb_name = "CaProduc.gdb" sub_folder1_path = r"..\..\Test\OutPutSpace" geoDataBs = os.listdir(sub_folder1_path) for gdb in geoDataBs: if arcpy.Exists(gdb_name): print gdb_name, " is Exist", "\n" else: arcpy.CreateFileGDB_management(sub_folder1_path, gdb_name) print gdb_name, "\n"