Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

RPA.FileSystem

Returns the absolute path to a file, and resolves symlinks.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path that will be resolved
return:absolute path to file as a string

Appends binary content to the given file.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
contentAnynull

See Create Binary File for usage example.

param path:path to file to append to
param content:content to append

Appends text to the given file.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
contentstrnull
encodingstrutf-8

See Create File for usage example.

param path:path to file to append to
param content:content to append
param encoding:character encoding of appended content

Replaces file extension for file at given path. the file extension can be removed by passing an empty string.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
extensionstrnull
param path:path to file to rename
param extension:new extension, e.g. .xlsx

Usage

*** Tasks *** Change a file extension Change file extension ... devdata/work-items-in/default/orders.xls ... .xlsx

Copy directory from source path to destination path.

Arguments

ArgumentTypeDefault value
sourcestr, Pathnull
destinationstr, Pathnull
param source:path to source directory
param destination:path to copy destination

Usage

*** Tasks *** Copy a directory Copy directory output temp

Copy a file from source path to destination path.

Arguments

ArgumentTypeDefault value
sourcestr, Pathnull
destinationstr, Pathnull

See Is Directory Empty for usage example.

param source:path to source file
param destination:path to copy destination

Copy multiple files to destination folder.

Arguments

ArgumentTypeDefault value
sourcesList[str | Path]null
destinationstr, Pathnull
param sources:list of source files
param destination:path to destination folder

Usage

*** Tasks *** Copy some files ${files}= Find files devdata/*.json Copy files ${files} output

Creates a new binary file, and writes content if any is given.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
contentAny, NoneNone
overwriteboolFalse
param path:path to file to write
param content:content to write to file (optional)
param overwrite:replace destination file if it already exists

Usage

*** Tasks *** Create a new file ${content}= Get ... url=https://file-examples.com/storage/fe88505b6162b2538a045ce/2017/10/file_example_JPG_100kB.jpg Create binary file output/sample.jpg content=${content.content} overwrite=${True}

Creates a directory and (optionally) non-existing parent directories.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
parentsboolFalse
exist_okboolTrue
param path:path to new directory
param parents:create missing parent directories (defaults to False)
param exist_ok:continue without errors if directory already exists (defaults to True)

Usage

*** Tasks *** Create new path Create directory output/my/new/path parents=${True}

Creates a new text file, and writes content if any is given.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
contentstr, NoneNone
encodingstrutf-8
overwriteboolFalse
param path:path to file to write
param content:content to write to file (optional)
param encoding:character encoding of written content (default utf-8)
param overwrite:replace destination file if it already exists (default False)

Usage

*** Tasks *** Create a new file ${content}= Get url=https://www.example.com Create file output/newfile.html content=${content.text} ... overwrite=${True}

Returns True if the given directory exists, False if not.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull

See Does Directory Not Exist for usage example.

param path:path to inspected directory
return:true or false if the directory exists

Returns True if the directory does not exist, False if it does.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to inspected directory
return:true or false if the directory does not exists

Usage

*** Tasks *** Check for directory ${directory_exists}= Does directory not exist output IF ${directory_exists} Create directory output

Returns True if the given file exists, False if not.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to inspected file
return:true or false if file exists

Usage

*** Tasks *** Check for file ${log_exists}= Does file exist output/log.html IF ${log_exists} ${file}= Find files output/log.html Open user browser ${file}[0] END

Returns True if the file does not exist, False if it does.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull

See Does File Exist for usage example.

param path:path to inspected file
return:true or false if the files does not exist

Removes all the files in the given directory.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:directory to remove files from

Usage

*** Tasks *** Empty out directory Empty directory output

Find files recursively according to a pattern.

Arguments

ArgumentTypeDefault value
patternstr, Pathnull
include_dirsboolTrue
include_filesboolTrue
param pattern:search path in glob format pattern, e.g. .xls or */orders.txt
param include_dirs:include directories in results (defaults to True)
param include_files:include files in results (defaults to True)
return:list of paths that match the pattern

Usage

*** Tasks *** Finding files recursively ${files}= Find files **/*.log FOR ${file} IN @{files} Read file ${file} END

Returns the creation time in seconds. Note: Linux sets this whenever file metadata changes

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file to inspect
return:creation time in seconds as a float

Returns the suffix for the file.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file
return:file suffix as a string

Returns the modified time in seconds.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file to inspect
return:modified time in seconds as a float

Returns only the full file name portion of a path.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file
return:filename portion of a path as a string

Return the name of the user who owns the file.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file to inspect
return:file owner as a string

Returns the file size in bytes.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file to inspect
return:file size in bytes as an int

Returns the name of the file without its extension.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file
return:filename without its suffix as a string

Returns True if the given directory has no files or subdirectories.

Arguments

ArgumentTypeDefault value
pathstr, Path, NoneNone
param path:path to inspected directory
return:true or false if the directory is empty

Usage

*** Tasks *** Check for empty directory ${directory_empty}= Is directory empty output IF ${directory_empty} Copy file ${source} output/new_file.txt END

Returns True if the given directory has any files or subdirectories.

Arguments

ArgumentTypeDefault value
pathstr, Path, NoneNone

See Is Directory Empty for usage example.

param path:path to inspected directory
return:true or false if the directory is not empty

Returns True if the given file has no content, i.e. has zero size.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to inspected file
return:true or false if the file is empty

Returns True if the given file has content, i.e. larger than zero size.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to inspected file
return:true or false if the file is not empty

Usage

*** Tasks *** Check for empty file ${file_empty}= Is file not empty output/log.html IF ${file_empty} Copy file output/log.html ${alt_dir} END

Joins multiple parts of a path together.

Arguments

ArgumentTypeDefault value
partsstr, Pathnull
param parts:Components of the path, e.g. dir, subdir, filename.ext
return:complete file path as a single string

Usage

*** Tasks *** Join path together Join path output/nested folder

Lists all the directories in the given directory, relative to it.

Arguments

ArgumentTypeDefault value
pathstr, Path, NoneNone
param path:base directory for search, defaults to current working dir
return:list of directories in selected directory

Usage

*** Tasks *** List directories ${directories}= List directories in directory devdata FOR ${path} IN @{directories} Log ${path} END

Lists all the files in the given directory, relative to it.

Arguments

ArgumentTypeDefault value
pathstr, Path, NoneNone
param path:base directory for search, defaults to current working directory
return:list of files in directory

Usage

*** Tasks *** List directory file ${files}= List files in directory output FOR ${file} IN @{files} Log ${file} END

Logs all the files in the directory recursively.

Arguments

ArgumentTypeDefault value
pathstr, Path, NoneNone
param path:base directory to start from, defaults to current working dir

Usage

*** Tasks *** List directory tree Log directory tree

Move a directory from source path to destination path.

Arguments

ArgumentTypeDefault value
sourcestr, Pathnull
destinationstr, Pathnull
overwriteboolFalse
param source:source directory path for moving
param destination:path to move to
param overwrite:replace destination directory if it already exists (defaults to False)

Usage

*** Tasks *** Move a directory Move directory output temp

Move a file from source path to destination path, optionally overwriting the destination.

Arguments

ArgumentTypeDefault value
sourcestr, Pathnull
destinationstr, Pathnull
overwriteboolFalse
param source:source file path for moving
param destination:path to move to
param overwrite:replace destination file if it already exists (defaults to False)

Usage

*** Tasks *** Move a file Create directory temp Move file output/log.html temp/log.html

Move multiple files to the destination folder.

Arguments

ArgumentTypeDefault value
sourcesList[str | Path]null
destinationstr, Pathnull
overwriteboolFalse
param sources:list of files to move
param destination:path to move destination
param overwrite:replace destination files if they already exist

Usage

*** Tasks *** Move some files Create directory temp Move files output/log.html output/output.xml temp

Removes redundant separators or up-level references from path.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path that will be normalized
return:path to file as a string

Usage

*** Tasks *** Get normal path # Normalized path becomes ../inputs/input.xlsx ${normalized_path}= Normalize path ..//inputs/./new/../input.xlsx Create work items ${normalized_path}

Reads a file in binary mode and returns the content. Does not attempt to decode the content in any way.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file to read
return:the file content as bytes

Usage

*** Tasks *** Read picture as binary ${pictures}= Find files **/*.png FOR ${picture} IN @{pictures} Read binary file ${picture} END

Reads a file as text, with given encoding, and returns the content."

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
encodingstrutf-8

See Find Files for usage example.

param path:path to file to read
param encoding:character encoding of file (default utf-8)
return:file content as string

Removes the given directory, and optionally everything it contains.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
recursiveboolFalse
param path:path to directory
param recursive:remove all subdirectories and files (default to False)

Usage

*** Tasks *** Delete a directory Remove directory output recursive=${True}

Removes the given file.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
missing_okboolTrue
param path:path to the file to remove
param missing_ok:ignore non-existent file (defaults to True)

Usage

*** Tasks *** Delete a file Remove file output/log.html

Removes multiple files.

Arguments

ArgumentTypeDefault value
pathsstr, Pathnull
missing_okboolTrue
param paths:paths to files to be removed
param missing_ok:ignore non-existent files (default to True)

Usage

*** Tasks *** Delete some files Remove files output/log.html output/output.xml

If file exists at path, execute given keyword with arguments.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
keywordstrnull
argsnull
param path:path to file to inspect
param keyword:Robot Framework keyword to execute
param args:arguments to keyword

Usage

*** Tasks *** Execute if orders exists Run keyword if file exists orders.xlsx Process orders

Creates a file with no content, or if file already exists, updates the modification and access times.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
param path:path to file which is touched

Poll path until it exists, or raise exception if timeout is reached.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
timeoutint, float5.0
param path:path to poll
param timeout:time in seconds until keyword fails
return:path to the created file as a string

Usage

*** Tasks *** Wait for existence Wait until created orders.xlsx 10 Process orders orders.xlsx

Poll path until it has been modified after the keyword was called, or raise exception if timeout is reached.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
timeoutint, float5.0
param path:path to poll
param timeout:time in seconds until keyword fails
return:path to the modified file as a string

Usage

*** Tasks *** Wait for change Wait until modified orders.xlsx 10 Process orders orders.xlsx

Poll path until it doesn't exist, or raise exception if timeout is reached.

Arguments

ArgumentTypeDefault value
pathstr, Pathnull
timeoutint, float5.0
param path:path to poll
param timeout:time in seconds until keyword fails