File
File actions allow interacting with files and folders on the robot host.
Note: action returns are mapped to robot state variables — for example, if an action returns {'filename': 'a.txt'} you access it as $filename in the flow.
Below we document only the actions annotated with @decorators.robotaction found in file.py.
Actions
file.copy
Copy a file or folder.
Parameters:
source— source file/folder path.destination— destination path.
Return:
none.
Exceptions:
FileNotFoundExceptionif source/destination is wrong or copy fails.
file.create_folder
Create a new folder (only the last path segment is created).
Parameters:
path— path for the new folder.
Return:
none.
Exceptions:
FileNotFoundExceptionif the path cannot be created.
file.delete
Delete a file or folder.
Parameters:
path— path to delete.
Return:
none.
Exceptions:
FileNotFoundExceptionif the path does not exist.
file.download
Download a file from a URL to a local path.
Parameters:
url— URL to download from.filepath— destination local path.
Return:
none.
file.file_exists
Check if a file exists.
Parameters:
path— path to check.
Return:
exists— boolean (True/False).
file.folder_exists
Check if a folder exists.
Parameters:
path— path to check.
Return:
exists— boolean (True/False).
file.get_file_extension
Return the file extension (without the dot).
Parameters:
filepath— file path or name.
Return:
extension— file extension (e.g.pdf).
file.get_filename
Return the filename from a filepath (resolves assets internally).
Parameters:
filepath— path or asset reference.
Return:
filename— filename string (e.g.doc.pdf).
file.is_pdf_by_magic
Check whether a file starts with the %PDF- magic bytes (extension-agnostic).
Parameters:
path - path to the file on disk.
Return:
is_pdf - True when the file header matches a PDF signature.
magic_hex - hexadecimal representation of the bytes read from the file header.
Exceptions:
FileNotFoundException: if path does not exist or is not a file.
file.is_zip_by_magic
Check whether a file starts with ZIP archive signatures (PK header variants), regardless of file extension.
Parameters:
path - path to the file on disk.
Return:
is_zip - True when the file header matches a ZIP local/empty archive signature.
magic_hex - hexadecimal representation of the bytes read from the file header.
Exceptions:
FileNotFoundException: if path does not exist or is not a file.
file.list
List items (files and folders) matching a pattern.
Parameters:
path— path or pattern.
Return:
items— list of items.items_count— total number of items.
file.list_files
List files matching a pattern (supports *).
Parameters:
path— path or glob pattern (e.g.c:/temp/*.txt).
Return:
files— list of file paths.files_count— number of returned files.
file.list_folders
List folders matching a pattern.
Parameters:
path— path or pattern.
Return:
folders— list of folder paths.folders_count— number of folders.
file.move
Move a file or folder.
Parameters:
source— source path.destination— destination path.
Return:
none.
Exceptions:
FileNotFoundExceptionif source/destination is wrong or move fails.
file.newest_file
Return the newest file path in a folder (supports patterns).
Parameters:
path— folder path or pattern (may end with/or\\).
Return:
path— full path of the most recent file.
file.rename
Rename a file or folder (calls file.move internally).
Parameters:
source— current path.destination— new path/name.
Return:
none.
file.size
Return file size in bytes, KB and MB.
Parameters:
path— file path.
Return:
size— bytes.sizeKB— kilobytes (float).sizeMB— megabytes (float).
file.to_base64
Convert file content to a base64 string.
Parameters:
filepath— path or asset reference.
Return:
base64— base64-encoded string of the file content.
file.unzip
Extract a ZIP file to a destination folder.
Parameters:
zip_file— path to the .zip file.extract_folder— destination folder.
Return:
none.
file.zip
Create a ZIP archive from a single file or from all files under a folder.
Parameters:
source - path to the file or folder to compress.
zip_file - destination path for the .zip file to create.
Return:
This action gives no return
Exceptions:
FileNotFoundException: if source does not exist.