From 5cd934ab581139d9154fe2f99eaf743dc857b723 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauldmccarthy@gmail.com>
Date: Sat, 7 Jul 2018 12:48:40 +0100
Subject: [PATCH] ENH: New path function to return all files in ditectory

---
 fsl/utils/path.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/fsl/utils/path.py b/fsl/utils/path.py
index 76efc7760..fc8efeadb 100644
--- a/fsl/utils/path.py
+++ b/fsl/utils/path.py
@@ -13,6 +13,7 @@ paths.
 
    deepest
    shallowest
+   allFiles
    hasExt
    addExt
    removeExt
@@ -24,8 +25,9 @@ paths.
 """
 
 
-import            glob
 import os.path as op
+import            os
+import            glob
 
 
 class PathError(Exception):
@@ -78,6 +80,20 @@ def shallowest(path, suffixes):
     return None
 
 
+def allFiles(root):
+    """Return a list containing all files which exist underneath the specified
+    ``root`` directory.
+    """
+
+    files = []
+
+    for dirpath, _, filenames in os.walk(root):
+        filenames = [op.join(dirpath, f) for f in filenames]
+        files.extend(filenames)
+
+    return files
+
+
 def hasExt(path, allowedExts):
     """Convenience function which returns ``True`` if the given ``path``
     ends with any of the given ``allowedExts``, ``False`` otherwise.
-- 
GitLab