Utils
provide.foundation.file.utils
¶
TODO: Add module docstring.
Functions¶
backup_file
¶
Create backup copy of file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
File to backup |
required |
suffix
|
str
|
Backup suffix |
'.bak'
|
timestamp
|
bool
|
If True, add timestamp to backup name |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to backup file, or None if source doesn't exist |
Source code in provide/foundation/file/utils.py
find_files
¶
Find files matching pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
Glob pattern (e.g., ".py", "**/.json") |
required |
root
|
Path | str
|
Root directory to search from |
'.'
|
recursive
|
bool
|
If True, search recursively |
True
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
List of matching file paths |
Source code in provide/foundation/file/utils.py
get_mtime
¶
Get modification time, None if not exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
File path |
required |
Returns:
| Type | Description |
|---|---|
float | None
|
Modification time as timestamp, or None if doesn't exist |
Source code in provide/foundation/file/utils.py
get_size
¶
Get file size in bytes, 0 if not exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
File path |
required |
Returns:
| Type | Description |
|---|---|
int
|
Size in bytes, or 0 if file doesn't exist |
Source code in provide/foundation/file/utils.py
touch
¶
Create empty file or update timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
File path |
required |
mode
|
int
|
File permissions for new files |
420
|
exist_ok
|
bool
|
If False, raise error if file exists |
True
|
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If exist_ok=False and file exists |