diff --git a/fsl/utils/path.py b/fsl/utils/path.py index 76efc7760f03348b2b3d96c8d21f7f3c7d09930f..fc8efeadb4426a245a72ffe60a63cb6264784d8d 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.