Skip to main content
File System & Path

File System & Path #

The best library I have found to handle file path is glob.

import glob

Enumerate Files #

List all second level subfolders:

list_sub = []

for folder in glob.glob("**/**/"):

List all subfolders recursively: (credit)

list_sub_r = []

for folder in glob.glob("**/", recursive=True):

List all .md files in each subfolder, recursively:

dict_all_files = {}

# for each folder
for folder in glob.glob("**/", recursive=True):
    dict_all_files[folder] = []

    # find all md files in the sub folder
    for file in glob.glob(folder + "*.md"):

# pretty print
print(json.dumps(dict_all_files, sort_keys=True, indent=4))