import subprocess from os import PathLike from typing import ( Union, ) def find(basedir: PathLike, **flags: str | bytes) -> list[bytes]: cmdline: list[Union[str, bytes, PathLike]] = ['find', basedir] for key, value in flags.items(): cmdline += [f'-{key}', value] cmdline.append('-print0') cmd = subprocess.run(cmdline, capture_output=True) return cmd.stdout.split(b'\0')[:-1]