FileUtils Documentation
*** Settings ***
Library FileUtils
*** Test Cases ***
Example
[Documentation] Demonstrates using FileUtils
# add your keyword calls here
Introduction
File and directory utilities for Robot Framework.
This library provides comprehensive file system operations including:
- File reading and writing
- Directory creation and management
- File copying and moving
- Path manipulation
- File existence checks
Arguments
Return Type
strDocumentation
Read entire content of a file.
Arguments:
file_path: Path to the file to readencoding: File encoding (default: utf-8)
Returns: File content as string
Example:
*** Settings *** Library FileUtils *** Test Cases *** Read File Example ${content} Read File Content /path/to/file.txt Should Not Be Empty ${content}
Arguments
Documentation
Write content to a file.
Creates the file if it doesn't exist, overwrites if it does.
Arguments:
file_path: Path where to write the filecontent: Content to writeencoding: File encoding (default: utf-8)
Example:
*** Settings *** Library FileUtils *** Test Cases *** Write File Example Write File Content output.txt Hello World File Should Exist output.txt
Arguments
Return Type
boolDocumentation
Check if a file exists.
Arguments:
file_path: Path to check
Returns: True if file exists, False otherwise
Arguments
Return Type
boolDocumentation
Check if a directory exists.
Arguments:
dir_path: Directory path to check
Returns: True if directory exists, False otherwise
Arguments
Documentation
Create a directory.
Arguments:
dir_path: Directory path to createparents: Create parent directories if needed (default: True)
Example:
*** Settings *** Library FileUtils *** Test Cases *** Create Directory Example Create Directory /path/to/new/directory Directory Should Exist /path/to/new/directory
Arguments
Documentation
Copy a file from source to destination.
Arguments:
source: Source file pathdestination: Destination file path
Example:
*** Settings *** Library FileUtils *** Test Cases *** Copy File Example Copy File source.txt backup/source.txt File Should Exist backup/source.txt
Arguments
Documentation
Move a file from source to destination.
Arguments:
source: Source file pathdestination: Destination file path
Arguments
Documentation
Delete a file.
Arguments:
file_path: Path to file to delete
Raises: FileNotFoundError if file doesn't exist
Arguments
Return Type
List[str]Documentation
List all files in a directory.
Arguments:
directory: Directory path to listpattern: Optional glob pattern to filter files (e.g., "*.txt")
Returns: List of file paths
Example:
*** Settings *** Library FileUtils *** Test Cases *** List Files Example ${files} List Files /path/to/dir *.txt Should Not Be Empty ${files}
Arguments
Return Type
intDocumentation
Get file size in bytes.
Arguments:
file_path: Path to file
Returns: File size in bytes
Arguments
Return Type
dictDocumentation
Read and parse a JSON file.
Arguments:
file_path: Path to JSON file
Returns: Parsed JSON as dictionary
Example:
*** Settings *** Library FileUtils *** Test Cases *** Read JSON File Example ${data} Read Json File config.json Should Be Equal ${data}[key] value
Arguments
Documentation
Write data to a JSON file.
Arguments:
file_path: Path where to write JSON filedata: Dictionary to write as JSONindent: JSON indentation (default: 2)
Example:
*** Settings *** Library FileUtils *** Test Cases *** Write JSON File Example ${config} Create Dictionary key=value name=test Write Json File config.json ${config} File Should Exist config.json
Arguments
Return Type
strDocumentation
Get file extension.
Arguments:
file_path: File path
Returns: File extension (without dot)
Example:
*** Settings *** Library FileUtils *** Test Cases *** Get File Extension Example ${ext} Get File Extension document.pdf Should Be Equal ${ext} pdf
Arguments
Return Type
strDocumentation
Join multiple path components.
Arguments:
*paths: Variable number of path components
Returns: Joined path string
Example:
*** Settings *** Library FileUtils *** Test Cases *** Join Paths Example ${path} Join Paths /home user documents file.txt Should Be Equal ${path} /home/user/documents/file.txt
Need Help?
Found an issue or have a feature request for this library? Let the maintainers know by opening a new GitHub issue. Please include environment details and relevant log output to help us reproduce the problem.