fabricatio_tool.fs.curd

File system create, update, read, delete operations.

Functions

dump_text(→ None)

Dump text to a file. you need to make sure the file's parent directory exists.

copy_file(→ None)

Copy a file from source to destination.

move_file(→ None)

Move a file from source to destination.

delete_file(→ None)

Delete a file.

create_directory(→ None)

Create a directory.

delete_directory(→ None)

Delete a directory and its contents.

absolute_path(→ str)

Get the absolute path of a file or directory.

gather_files(→ list[str])

Gather all files with a specific extension in a directory.

Module Contents

fabricatio_tool.fs.curd.dump_text(path: str | pathlib.Path, text: str) None

Dump text to a file. you need to make sure the file’s parent directory exists.

Parameters:
  • path (str, Path) – Path to the file

  • text (str) – Text to write to the file

Returns:

None

fabricatio_tool.fs.curd.copy_file(src: str | pathlib.Path, dst: str | pathlib.Path) None

Copy a file from source to destination.

Parameters:
  • src – Source file path

  • dst – Destination file path

Raises:
fabricatio_tool.fs.curd.move_file(src: str | pathlib.Path, dst: str | pathlib.Path) None

Move a file from source to destination.

Parameters:
  • src – Source file path

  • dst – Destination file path

Raises:
fabricatio_tool.fs.curd.delete_file(file_path: str | pathlib.Path) None

Delete a file.

Parameters:

file_path – Path to the file to be deleted

Raises:
fabricatio_tool.fs.curd.create_directory(dir_path: str | pathlib.Path, parents: bool = True, exist_ok: bool = True) None

Create a directory.

Parameters:
  • dir_path – Path to the directory to create

  • parents – Create parent directories if they don’t exist

  • exist_ok – Don’t raise error if directory already exists

fabricatio_tool.fs.curd.delete_directory(dir_path: str | pathlib.Path) None

Delete a directory and its contents.

Parameters:

dir_path – Path to the directory to delete

Raises:
fabricatio_tool.fs.curd.absolute_path(path: str | pathlib.Path | os.PathLike) str

Get the absolute path of a file or directory.

Parameters:

path (str, Path, PathLike) – The path to the file or directory.

Returns:

The absolute path of the file or directory.

Return type:

str

fabricatio_tool.fs.curd.gather_files(directory: str | pathlib.Path | os.PathLike, extension: str) list[str]

Gather all files with a specific extension in a directory.

Parameters:
  • directory (str, Path, PathLike) – The directory to search in.

  • extension (str) – The file extension to look for.

Returns:

A list of file paths with the specified extension.

Return type:

list[str]

Example

>>> gather_files('/path/to/directory', 'txt')
['/path/to/directory/file1.txt', '/path/to/directory/file2.txt']