File utilities
Kano provides some file-related functions:
list_files
: get a list of files paths inside a folder.list_folders
: get a list of folders paths inside a folder.print_foldertree
: print foldertree of a folder and additional information.zip_paths
: zip a list of files and folders.create_folder
: create a folder and its parent folders if they don't exist.remove_folder
: remove a folder and its contents.print_package_versions
: print packages listed in requirements file and their version in the current environment.
kano.file_utils.list_files(folder_path, return_absolute_paths=True)
List files in a folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Path to the folder. |
required |
return_absolute_paths |
bool
|
Whether to return absolute paths or relative paths. |
True
|
Returns:
Name | Type | Description |
---|---|---|
sorted_files_paths |
list
|
A list of file paths. |
Source code in kano\file_utils.py
kano.file_utils.list_folders(folder_path, return_absolute_paths=True)
List folders in a folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Path to the folder. |
required |
return_absolute_paths |
bool
|
Whether to return absolute paths or relative paths. |
True
|
Returns:
Name | Type | Description |
---|---|---|
sorted_folders_paths |
list
|
A list of folder paths. |
Source code in kano\file_utils.py
kano.file_utils.print_foldertree(folder_path, level=0, max_level=1, verbose=True)
Print the folder tree structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Path to the folder. |
required |
level |
int
|
Current level to apply recursion, you do not need to provide this field. |
0
|
max_level |
int
|
Maximum level of folder tree. |
1
|
verbose |
bool
|
Whether to print additional details. |
True
|
Source code in kano\file_utils.py
kano.file_utils.zip_paths(paths, output_zip)
Create a ZIP file containing specified paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths |
list
|
List of file or folder paths to be included in the ZIP file. |
required |
output_zip |
str
|
Path to save the output ZIP file. |
required |
Source code in kano\file_utils.py
kano.file_utils.create_folder(folder_path)
Create a folder if it doesn't exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Path to the folder to be created. |
required |
kano.file_utils.remove_folder(folder_path)
Remove a folder and its contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Path to the folder to be removed. |
required |
Source code in kano\file_utils.py
kano.file_utils.print_package_versions(requirements_file_path='requirements.txt')
Print packages listed in requirements file and their version in the current environment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
requirements_file_path |
str
|
path to a file contain packages names |
'requirements.txt'
|