Commit 5cd934ab authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

ENH: New path function to return all files in ditectory

parent 57ed2024
...@@ -13,6 +13,7 @@ paths. ...@@ -13,6 +13,7 @@ paths.
deepest deepest
shallowest shallowest
allFiles
hasExt hasExt
addExt addExt
removeExt removeExt
...@@ -24,8 +25,9 @@ paths. ...@@ -24,8 +25,9 @@ paths.
""" """
import glob
import os.path as op import os.path as op
import os
import glob
class PathError(Exception): class PathError(Exception):
...@@ -78,6 +80,20 @@ def shallowest(path, suffixes): ...@@ -78,6 +80,20 @@ def shallowest(path, suffixes):
return None 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): def hasExt(path, allowedExts):
"""Convenience function which returns ``True`` if the given ``path`` """Convenience function which returns ``True`` if the given ``path``
ends with any of the given ``allowedExts``, ``False`` otherwise. ends with any of the given ``allowedExts``, ``False`` otherwise.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment