# remember those lines #from pathlib import Path #Path("/root/dirA/dirB").mkdir(parents=True, exist_ok=True) import os # funcion que recibe un cadena y crea un direcorio que recibe como nombre dicha cadena def make_directories(file): file = str(file) file_path = os.path.join(base_dir, file) if os.path.exists(file_path) == False: os.mkdir(file_path) print('Directorio creado :' + file_path) else: print('El directorio: ' + file_path + ' ya existe!!!') from pathlib import Path # creacion de directorios en 2 niveles def make_2_level_directories(root_folder_name, directories_to_make=[]): new_path_dir= [] new_path_root = file_path = os.path.join(base_dir, root_folder_name) Path(new_path_root).mkdir(parents=True, exist_ok=True) if len(directories_to_make) == 0: return print("No hay subdirectorios para crear") for file in directories_to_make : new_path = os.path.join(root_folder_name,file) new_path_dir.append(new_path) for file in new_path_dir: make_directories(file) # no olvidar cambiar el directorio base
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter