Filesystem

Bash

Tasks related to managing unix-level operations like file and directory management

tamr_toolbox.filesystem.bash.create_directories(directories, *, require_absolute_path=True, failure_if_exists=False)[source]

Creates directories recursively from a list of target directories if not already created

Parameters
  • directories (List[Union[Path, str]]) – List of directories to create.

  • require_absolute_path (bool) – Boolean flag indicating whether to require absolute paths.

  • failure_if_exists (bool) – Boolean flag requiring failure if attempt to create a directory that already exists.

Return type

None

Returns

None

tamr_toolbox.filesystem.bash.remove_directories(directories, *, require_absolute_path=True, failure_if_not_exists=False, allow_recursive_deletes=False)[source]

Removes directories from a list of target directories if created. The directory must be empty

Parameters
  • directories (List[Union[Path, str]]) – List of directories to remove

  • require_absolute_path (bool) – Boolean flag indicating whether to require absolute paths.

  • failure_if_not_exists (bool) – Boolean flag requiring failure if attempt to remove a directory that does not exist.

  • allow_recursive_deletes (bool) – Boolean flag indicating whether to allow recursive deletion.

Return type

None

Returns

None

tamr_toolbox.filesystem.bash.delete_old_files(data_path, *, num_days_to_keep, exclude_paths=None)[source]

Find all files in the directory data_path and its subdirectory which have not been modified for a specified number of days and delete them except if their subdirectory is specified in the folders to exclude

Parameters
  • data_path (Union[Path, str]) – path to the root folder from where to search for files

  • num_days_to_keep (int) – number of days to keep files for

  • exclude_paths (Optional[List[Union[Path, str]]]) – list of path to exclude from the search

Return type

List[str]

Returns

A list of deleted files

Raises