added pure python version of lsdir

This commit is contained in:
marco cammarata 2017-06-19 09:34:51 +02:00
parent 585c57c33a
commit fec26c58b2
1 changed files with 16 additions and 1 deletions

View File

@ -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: