Skip to content

Instantly share code, notes, and snippets.

@KTZgraph
Created July 20, 2022 00:38
Show Gist options
  • Save KTZgraph/ce0f60b445d1869bc98e9dce61c6d24f to your computer and use it in GitHub Desktop.
Save KTZgraph/ce0f60b445d1869bc98e9dce61c6d24f to your computer and use it in GitHub Desktop.

Revisions

  1. KTZgraph created this gist Jul 20, 2022.
    24 changes: 24 additions & 0 deletions create_dir_structure.py
    Original 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")