Created
July 20, 2022 00:38
-
-
Save KTZgraph/ce0f60b445d1869bc98e9dce61c6d24f to your computer and use it in GitHub Desktop.
Revisions
-
KTZgraph created this gist
Jul 20, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ import os def get_folder_structure(dst_filepath: str)->list[str]: folders_list = dst_filepath.split("/") f_length = len(folders_list) structure = [] for deph in range(f_length): tmp_path = [folders_list[i] for i in range(deph)] tmp_path = ("/").join(tmp_path) if tmp_path != "": structure.append(tmp_path) return structure def create_folder_structure(dst_filepath: str)->None: structure = get_folder_structure(dst_filepath) for path_s in structure: if not os.path.isdir(path_s): os.mkdir(path_s) create_folder_structure("dir_here/nested_1/nested_2/nested_3/nested_n/myfile.txt") create_folder_structure("dir_here_brother/nested_1/nested_2/nested_3/nested_n/myfile.txt") create_folder_structure("dir_here_brother/nested_111/myfile.txt")