Class containing only classmethod to simplify file management
Functions
Return the extension of a file without the '.' if it is present on first caracter
Name | Type | Default value | Description |
---|---|---|---|
extension | str | Extension of the file |
str |
Copy a directory from source to destination
Name | Type | Default value | Description |
---|---|---|---|
source_path | Union | Source directory path pathtype | |
destination_path | Union | Destination directory path pathtype |
Copy the content of a directory to another directory
Name | Type | Default value | Description |
---|---|---|---|
source_dir_path | Union | Source directory path pathtype | |
destination_dir_path | Union | Destination directory path pathtype |
Copy a file from source to destination
Name | Type | Default value | Description |
---|---|---|---|
source_path | Union | Source file path pathtype | |
destination_path | Union | Destination file path pathtype |
Copy a file or a directory from source to destination
Name | Type | Default value | Description |
---|---|---|---|
source_path | Union | Source file or directory path pathtype | |
destination_path | Union | Destination file or directory path pathtype |
Create a directory and all intermediate directories if they do not exist
Name | Type | Default value | Description |
---|---|---|---|
dir_path | Union | Path to the directory pathtype |
Path |
Create an empty file if it does not exist. Creates intermediate directories if needed.
Name | Type | Default value | Description |
---|---|---|---|
file_path | Union | Path to the file pathtype |
Path |
Create a FastAPI FileResponse from a file path
:raises FileNotFoundError: if the file does not exist
Name | Type | Default value | Description |
---|---|---|---|
file_path | Union | Path to the file pathtype | |
filename | str | Name of the file, defaults to none , optional | |
media_type | str | Media type of the file, defaults to none , optional |
FileResponse |
Delete a directory and all its content
Name | Type | Default value | Description |
---|---|---|---|
dir_path | Union | Path to the directory pathtype | |
ignore_errors | bool | True | If true, do not raise an exception if the directory does not exist, defaults to true , optional |
Delete all the content of a directory but not the directory itself.
Name | Type | Default value | Description |
---|---|---|---|
dir_path | Union | Path to the directory to empty pathtype | |
ignore_errors | bool | True | If true, do not raise an exception if the directory does not exist, defaults to true , optional |
Delete a file
Name | Type | Default value | Description |
---|---|---|---|
file_path | Union | Path to the file pathtype | |
ignore_errors | bool | True | If true, do not raise an exception if the file does not exist, defaults to true , optional |
Delete a file or a directory
Name | Type | Default value | Description |
---|---|---|---|
node_path | Union | Path to the file or directory pathtype | |
ignore_errors | bool | True | If true, do not raise an exception if the node does not exist, defaults to true , optional |
Detect the encoding of a file using charset-normalizer.
Name | Type | Default value | Description |
---|---|---|---|
file_path | Union | Path to the file pathtype | |
default_encoding | str | utf-8 | Default encoding to use if the encoding is not detected, defaults to 'utf-8' , optional |
str |
Exist on local machine
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
Return the parent directory of a file or a folder
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
Path |
Return the content of a directory as a json nested object.
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the directory pathtype |
Any |
Return the name of the folder. If the path is a file, return the name of the parent folder. If the path is a folder, return the name of the folder.
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
Return the extension of a file without the '.'. Return None if no extension is found (like folder).
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
str |
Return the extension of a file from its content type
Name | Type | Default value | Description |
---|---|---|---|
content_type | str | Content type of the file |
str |
Return a human readable size from a size in bytes. Ex : 1024 -> 1 KB
Name | Type | Default value | Description |
---|---|---|---|
size | float | Size in bytes |
str |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
str |
Return the name of the file without the extension or the name of the folder
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
Return the name of the file with the extension or the name of the folder
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
Return a Path object from a string or a Path object
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to convert pathtype |
Path |
Return the size of a file or a folder. For folder, it is the sum of the size of all files in the folder (recursive).
Name | Type | Default value | Description |
---|---|---|---|
path | Union | Path to the file or folder pathtype |
int |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Name | Type | Default value | Description |
---|---|---|---|
path | Union |
bool |
Move a file or a directory from source to destination
Name | Type | Default value | Description |
---|---|---|---|
source_path | Union | Source file or directory path pathtype | |
destination_path | Union | Destination file or directory path pathtype |
Sanitize a file name, folder name or path in order to prevent injection when using the file name Basically, it keeps only the alphanumeric characters and -,_,,/
Name | Type | Default value | Description |
---|---|---|---|
name | str | Name to sanitize |
str |
Generate a unique fs node name for a list of node names. Append _1, _2... before the extension if the str is already in the list. Useful to avoid name collision when adding a file to a directory.
Name | Type | Default value | Description |
---|---|---|---|
fs_node_name | str | Name of the new fs node | |
dir_path | str | Path to the directory |
str |
Generate a unique fs node name for a list of node names. Append _1, _2... before the extension if the str is already in the list. Useful to avoid name collision when adding a file to a directory.
Name | Type | Default value | Description |
---|---|---|---|
list_fs_node_names | List | List of existing fs node names [str] | |
fs_node_name | str | Name of the new fs node |
str |