rosikand / rsbox

📦 A toolbox of utility functions I commonly use when programming in Python.
MIT License
0 stars 0 forks source link

Add get all subdirs function #10

Open rosikand opened 1 year ago

rosikand commented 1 year ago

In ML and vision, it is common to loop through a directory and retrieve all subdirectories. Thus, implement the following:

from glob import glob

def get_subdirs(root_path):
    return glob(root_path + "/*/", recursive = True)

avoids the need for the complicated import, adding the /*/ at the end of the path, and also the recursive parameter. Could also be useful to have a function that subsequently gets all files in that subdir:


def get_files(root_path):
    return glob(root_path + "/*")