fabricatio_tool.fs.curd
File system create, update, read, delete operations.
Functions
|
Dump text to a file. you need to make sure the file's parent directory exists. |
|
Copy a file from source to destination. |
|
Move a file from source to destination. |
|
Delete a file. |
|
Create a directory. |
|
Delete a directory and its contents. |
|
Get the absolute path of a file or directory. |
|
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.
- 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:
FileNotFoundError – If source file doesn’t exist
shutil.SameFileError – If source and destination are the same
- 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:
FileNotFoundError – If source file doesn’t exist
shutil.SameFileError – If source and destination are the same
- 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:
FileNotFoundError – If file doesn’t exist
PermissionError – If no permission to delete the file
- 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:
FileNotFoundError – If directory doesn’t exist
OSError – If directory is not empty and can’t be removed
ValueError – If attempting to delete root directory
- fabricatio_tool.fs.curd.absolute_path(path: str | pathlib.Path | os.PathLike) str
Get the absolute path of a file or directory.
- 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:
- Returns:
A list of file paths with the specified extension.
- Return type:
Example
>>> gather_files('/path/to/directory', 'txt') ['/path/to/directory/file1.txt', '/path/to/directory/file2.txt']