From fec26c58b2d5f26b840e0f0832692d35340ab1df Mon Sep 17 00:00:00 2001 From: marco cammarata Date: Mon, 19 Jun 2017 09:34:51 +0200 Subject: [PATCH] added pure python version of lsdir --- mcutils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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: