File
File module for dost. This module is used to interact with files.
Examples:
It contains the following functions:
read_text(path)
: Read a text file and return the content as a string.write_text(path, contents)
: Write a text file with the given content.copy(source, destination)
: Copy a file from the source to the destination.move(source, destination)
: Move a file from the source to the destination.delete(path)
: Delete a file at the given path.rename(path, new_name)
: Rename a file at the given path.create(path)
: Create a file at the given path.
copy(source, destination)
Copy a file from source to destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str || WindowsPath
|
The path to the source file. |
required |
destination |
str || WindowsPath
|
The path to the destination file. |
required |
Examples:
create(path)
delete(path)
move(source, destination)
Move a file from source to destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source |
str || WindowsPath
|
The path to the source file. |
required |
destination |
str || WindowsPath
|
The path to the destination file. |
required |
Examples:
read_text(path)
Reads a text file and returns its contents as a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str || list || WindowsPath
|
The path to the text file. |
required |
Returns:
Type | Description |
---|---|
Union[str, List[str]]
|
(str || list) :The contents of the text file. If a list of paths is provided, a list of strings is returned. |
Examples:
rename(path, new_name)
Rename a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str || WindowsPath
|
The path to the file. |
required |
new_name |
str
|
The new name of the file. |
required |
Examples:
write_text(path, contents)
Write a text file with the given contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str || WindowsPath
|
The path to the text file. |
required |
contents |
str
|
The contents of the text file. |
required |
Examples: