Skip to content

File Utils

File utilities for the Document Processing Orchestrator.

Contains utility functions for working with files, such as reading and writing files, and checking file paths.

create_folder(folder_path)

Create a folder.

This function check if the folder path exists. If the folder path does not exist, the function creates a folder in the specified folder path.

Parameters:

Name Type Description Default
folder_path str

The folder path to create.

required

create_full_path(dir_path, filename, file_extension)

Create a full path for a file.

This function creates a full path for a file by combining the directory path, the filename, and the file extension.

Parameters:

Name Type Description Default
dir_path str

The directory path.

required
filename str

The filename.

required
file_extension str

The file extension.

required

Returns:

Name Type Description
str str

The full path for the file.

read_json_file(file_path)

Read a JSON file.

This function reads a JSON file and returns the content of the JSON file.

Parameters:

Name Type Description Default
file_path str

The path of the JSON file to read.

required

Returns:

Type Description
list[dict[str, Any]] | dict[str, Any]

list[dict[str, Any]] | dict[str, Any]: The content of the JSON file.

save_file(content, filename)

Save the content to a file.

Parameters:

Name Type Description Default
content str

The content to save.

required
filename str

The filename to save the content to.

required

Returns:

Type Description

None

save_to_csv(elements, folder_path, file_name)

Save a list of elements to a CSV file.

This function saves a list of elements to a CSV file. The function takes the list of elements, the folder path, and the file name as input and saves the elements to a CSV file in the specified folder.

Parameters:

Name Type Description Default
elements list[dict[str, Any]]

The list of elements to save.

required
folder_path str

The folder path to save the CSV file.

required
file_name str

The file name of the CSV file.

required

Returns:

Type Description
None

None

save_to_json(elements, folder_path, file_name)

Save a list of elements to a JSON file.

This function saves a list of elements to a JSON file. The function takes the list of elements, the folder path, and the file name as input and saves the elements to a JSON file in the specified folder.

Parameters:

Name Type Description Default
elements list[dict[str, Any]] | dict[str, Any]

The list of elements to save.

required
folder_path str

The folder path to save the JSON file.

required
file_name str

The file name of the JSON file.

required

Returns:

Name Type Description
str str

The full filepath of the created JSON file.