Quellcode durchsuchen

Implement expression search in dirlist

master
Dirk Alders vor 2 Monaten
Ursprung
Commit
9237f6f7f7
1 geänderte Dateien mit 6 neuen und 6 gelöschten Zeilen
  1. 6
    6
      __init__.py

+ 6
- 6
__init__.py Datei anzeigen

@@ -62,11 +62,12 @@ __INTERPRETER__ = (3, )
62 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 67
     Function returning a list of directories below a given path.
68 68
 
69 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 71
     :param bool rekursive: search all subfolders if True.
71 72
     :returns: list of filenames including the pathe
72 73
     :rtype: list
@@ -82,12 +83,11 @@ def dirlist(path='.', rekursive=True):
82 83
     li = list()
83 84
     if os.path.exists(path):
84 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 89
                 if rekursive:
90
-                    li.extend(dirlist(fulldir))
90
+                    li.extend(dirlist(dirname))
91 91
     else:
92 92
         logger.warning('DIRLIST: path (%s) does not exist - empty filelist will be returned', path)
93 93
     return li

Laden…
Abbrechen
Speichern