pyppin.os.list_files

[View Source]

Recursively list all the files in a directory.

“Wait, isn’t that what os.ScanDir is for?” you ask. Well… sorta. That function isn’t recursive for a reason – correctly recursively listing things in the presence of file system links and the like is surprisingly subtle and subject to exciting bugs. This function is here so that you never have to worry about that again.

Functions

list_files(base[, recursive, select])

List all files (recursively) within the given directory.

pyppin.os.list_files.list_files(base: Union[str, Path], recursive: bool = True, select: Optional[Callable[[Path], bool]] = None) Iterator[Path][source]

List all files (recursively) within the given directory. It is guaranteed that no file will be listed twice, even if it appears twice due to symlinks.

Parameters
  • base – The base file or directory from which we should start the search.

  • recursive – If true, recurse into subdirectories.

  • select – If given, only examine directories for which the function returns True.

Yields

Paths of all matching files. These are absolute if base is absolute, or relative if base is relative. It is guaranteed that the yielded path is_relative_to(base).