summaryrefslogtreecommitdiff
path: root/files/data_io/utils/file_utils.py
blob: 0a1e84623ea662f2a55c1cd2ba93629f3a31513d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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