File Utilities

File Utils

class BBFileUtils

Bases: object

Utilities for reading/writing files.

classmethod delete_directory(directory_path, ignore_errors=False)

Delete a directory.

Parameters:
  • directory_path (str) – The directory to delete.

  • ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops). Default is False.

Returns:

True if successful. False if not.

Return type:

bool

classmethod delete_file(file_path, ignore_errors=False)

Delete a file.

Parameters:
  • file_path (str) – The file to delete.

  • ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops). Default is False.

Returns:

True if successful. False if not.

Return type:

bool

classmethod read_file(file_path, buffering=1, encoding='utf-8')

Read text from a file.

Parameters:
  • file_path (str) – The file to read from.

  • buffering (int, optional) – See the built-in python open() function documentation for more details.

  • encoding (str, optional) – See the built-in python open() function documentation for more details.

Returns:

The contents of the file as a string or None if an error occurred.

Return type:

Union[str, None]

classmethod write_file(file_path, text, buffering=1, encoding='utf-8', ignore_errors=False, remove_if_exists=False)

Write text to a file.

Parameters:
  • file_path (str) – The file to write to.

  • text (str) – The text to write.

  • buffering (int, optional) – See the built-in python open() function documentation for more details.

  • encoding (str, optional) – See the built-in python open() function documentation for more details.

  • ignore_errors (bool, optional) – If True, any exceptions thrown will be ignored (Useful in preventing infinite loops)

  • remove_if_exists (bool, optional) – If True and the File exists already, it will be deleted before writing the data. If False and the File exists already, the data will be appended to the end of it. Default is False.

Returns:

True if successful. False if not.

Return type:

bool

Game File Utils

class BBGameFileUtils

Bases: object

Utilities for reading/writing game related files.

classmethod get_the_sims_4_file_path()

Retrieve the full path of the folder ‘DocumentsElectronic ArtsThe Sims 4’

Returns:

The file path to ‘DocumentsElectronic ArtsThe Sims 4’ folder.

Return type:

str