diff --git a/mcutils.py b/mcutils.py index cf8198d..f39edc9 100644 --- a/mcutils.py +++ b/mcutils.py @@ -507,7 +507,7 @@ def getCMD(cmd,strip=True): ret = [x.strip() for x in ret] return ret -def lsdir(path,withQuotes=False,recursive=False): +def lsdir_old(path,withQuotes=False,recursive=False): if recursive: dirs = [] for (dir, _, file) in os.walk(path): dirs.append(dir) @@ -519,6 +519,21 @@ def lsdir(path,withQuotes=False,recursive=False): dirs = [ "'%s'" % x for x in dirs ] return dirs +def lsdir(folder="./",withQuotes=False,recursive=False): + if not recursive: + folders = list(os.scandir(folder)) + folders = [f.path for f in folders if f.is_dir()] + else: + folders = [] + def finddirs(path): + inside = list(os.scandir(path)) + inside = [f.path for f in inside if f.is_dir()] + folders.append( path ) + [finddirs(f) for f in inside] + finddirs(folder) + if (withQuotes): + folders = [ "'%s'" % x for x in folders ] + return folders def lsfiles(path,withQuotes=False,recursive=False): if recursive: