Browse Source

Implement expression search in dirlist

master
Dirk Alders 2 months ago
parent
commit
9237f6f7f7
1 changed files with 6 additions and 6 deletions
  1. 6
    6
      __init__.py

+ 6
- 6
__init__.py View File

62
 """The Tested Interpreter-Versions"""
62
 """The Tested Interpreter-Versions"""
63
 
63
 
64
 
64
 
65
-def dirlist(path='.', rekursive=True):
65
+def dirlist(path='.', expression='*', rekursive=True):
66
     """
66
     """
67
     Function returning a list of directories below a given path.
67
     Function returning a list of directories below a given path.
68
 
68
 
69
     :param str path: folder which is the basepath for searching files.
69
     :param str path: folder which is the basepath for searching files.
70
+    :param str expression: expression to fit including shell-style wildcards. It is only used for the first directory level, if rekursive is set to True.
70
     :param bool rekursive: search all subfolders if True.
71
     :param bool rekursive: search all subfolders if True.
71
     :returns: list of filenames including the pathe
72
     :returns: list of filenames including the pathe
72
     :rtype: list
73
     :rtype: list
82
     li = list()
83
     li = list()
83
     if os.path.exists(path):
84
     if os.path.exists(path):
84
         logger.debug('DIRLIST: path (%s) exists - looking for directories to append', path)
85
         logger.debug('DIRLIST: path (%s) exists - looking for directories to append', path)
85
-        for dirname in os.listdir(path):
86
-            fulldir = os.path.join(path, dirname)
87
-            if os.path.isdir(fulldir):
88
-                li.append(fulldir)
86
+        for dirname in glob.glob(os.path.join(path, expression)):
87
+            if os.path.isdir(dirname):
88
+                li.append(dirname)
89
                 if rekursive:
89
                 if rekursive:
90
-                    li.extend(dirlist(fulldir))
90
+                    li.extend(dirlist(dirname))
91
     else:
91
     else:
92
         logger.warning('DIRLIST: path (%s) does not exist - empty filelist will be returned', path)
92
         logger.warning('DIRLIST: path (%s) does not exist - empty filelist will be returned', path)
93
     return li
93
     return li

Loading…
Cancel
Save