idmtools.utils.file module#

utilities for files.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

idmtools.utils.file.scan_directory(basedir: str, recursive: bool = True, ignore_directories: List[str] | None = None) Iterable[DirEntry][source]#

Scan a directory recursively or not.

Parameters:
  • basedir – The root directory to start from.

  • recursive – True to search the sub-folders recursively; False to stay in the root directory.

  • ignore_directories – Ignore directories

Returns:

An iterator yielding all the files found.

idmtools.utils.file.file_content_to_generator(absolute_path, chunk_size=128) Generator[bytearray, None, None][source]#

Create a generator from file contents in chunks(useful for streaming binary data and piping).

Parameters:
  • absolute_path – absolute path to file

  • chunk_size – chunk size

Returns:

Generator that return bytes in chunks of size chunk_size

idmtools.utils.file.content_generator(content: str | bytes, chunk_size=128) Generator[bytearray, None, None][source]#

Create a generator from file contents in chunks(useful for streaming binary data and piping).

Parameters:
  • content – file content

  • chunk_size – chunk size

Returns:

Generator that return bytes in chunks of size chunk_size