autonomy_toolkit.utils.files#

Provides helper methods for interacting with the filesystem.

Module Contents#

Functions#

file_exists(→ bool)

Check if the passed filename is an actual file

search_upwards_for_file(→ pathlib.Path)

Search in the current directory and all directories above it

read_file(→ str)

Read in the passed file and return it as a string.

file_exists(filename: str, throw_error: bool = False, can_be_directory: bool = False) bool[source]#

Check if the passed filename is an actual file

Parameters:
  • filename (str) – The filename to check

  • throw_error (bool) – If True, will throw an error if the file doesn’t exist. Defaults to False.

  • can_be_directory (bool) – If True, will check if it is a directory, in addition to a file

Returns:

bool – True if the file exists, false otherwise

Throws:

FileNotFoundError: If filename is not a file and throw_error is set to true

search_upwards_for_file(filename: pathlib.Path | str) pathlib.Path[source]#

Search in the current directory and all directories above it for a file of a particular name.

Arg:

filename (str): the filename to look for.

Returns:

Path – the location of the first file found or None, if none was found

read_file(filename: pathlib.Path | str) str[source]#

Read in the passed file and return it as a string.

Parameters:

filename (str) – the file to read

Returns:

str – the file’s contents as a string