diff options
Diffstat (limited to 'files/data_io/utils/file_utils.py')
| -rw-r--r-- | files/data_io/utils/file_utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/files/data_io/utils/file_utils.py b/files/data_io/utils/file_utils.py new file mode 100644 index 0000000..0a1e846 --- /dev/null +++ b/files/data_io/utils/file_utils.py @@ -0,0 +1,15 @@ +import os + +def ensure_dir(path: str): + """Ensure that a directory exists.""" + if not os.path.exists(path): + os.makedirs(path) + +def list_files(root: str, suffix: str): + """Recursively list files ending with suffix.""" + matches = [] + for dirpath, _, filenames in os.walk(root): + for f in filenames: + if f.endswith(suffix): + matches.append(os.path.join(dirpath, f)) + return matches |
