RPA.FileSystem

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

Arguments

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

Appends binary content to the given file.

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to file to append to
contentAnynullcontent to append

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 valueDescription
pathstr, Pathnullpath to file to append to
contentstrnullcontent to append
encodingstrutf-8character encoding of appended content

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 valueDescription
pathstr, Pathnullpath to file to rename
extensionstrnullnew extension, e.g. .xlsx
param path:path to file to rename
param extension:
 new extension, e.g. .xlsx

Examples

*** 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 valueDescription
sourcestr, Pathnullpath to source directory
destinationstr, Pathnullpath to copy destination
param source:path to source directory
param destination:
 path to copy destination

Examples

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

Copy a file from source path to destination path.

Arguments

ArgumentTypeDefault valueDescription
sourcestr, Pathnullpath to source file
destinationstr, Pathnullpath to copy destination

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 valueDescription
sourcesList[str | Path]nulllist of source files
destinationstr, Pathnullpath to destination folder
param sources:list of source files
param destination:
 path to destination folder

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file to write
contentAny, NoneNonecontent to write to file (optional)
overwriteboolFalsereplace destination file if it already exists
param path:path to file to write
param content:content to write to file (optional)
param overwrite:
 replace destination file if it already exists

Examples

*** 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 valueDescription
pathstr, Pathnullpath to new directory
parentsboolFalsecreate missing parent directories (defaults to False)
exist_okboolTruecontinue without errors if directory already exists (defaults to True)
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)

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file to write
contentstr, NoneNonecontent to write to file (optional)
encodingstrutf-8character encoding of written content (default utf-8)
overwriteboolFalsereplace destination file if it already exists (default False)
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)

Examples

*** 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 valueDescription
pathstr, Pathnullpath to inspected directory

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 valueDescription
pathstr, Pathnullpath to inspected directory
param path:path to inspected directory
return:true or false if the directory does not exists

Examples

*** 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 valueDescription
pathstr, Pathnullpath to inspected file
param path:path to inspected file
return:true or false if file exists

Examples

*** 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 valueDescription
pathstr, Pathnullpath to inspected file

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 valueDescription
pathstr, Pathnulldirectory to remove files from
param path:directory to remove files from

Examples

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

Find files recursively according to a pattern.

Arguments

ArgumentTypeDefault valueDescription
patternstr, Pathnullsearch path in glob format pattern, e.g. .xls or */orders.txt
include_dirsboolTrueinclude directories in results (defaults to True)
include_filesboolTrueinclude files in results (defaults to True)
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

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file to inspect
param path:path to file to inspect
return:creation time in seconds as a float

Returns the suffix for the file.

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to file
param path:path to file
return:file suffix as a string

Returns the modified time in seconds.

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to file to inspect
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 valueDescription
pathstr, Pathnullpath to file
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 valueDescription
pathstr, Pathnullpath to file to inspect
param path:path to file to inspect
return:file owner as a string

Returns the file size in bytes.

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to file to inspect
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 valueDescription
pathstr, Pathnullpath to file
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 valueDescription
pathstr, Path, NoneNonepath to inspected directory
param path:path to inspected directory
return:true or false if the directory is empty

Examples

*** 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 valueDescription
pathstr, Path, NoneNonepath to inspected directory

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 valueDescription
pathstr, Pathnullpath to inspected file
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 valueDescription
pathstr, Pathnullpath to inspected file
param path:path to inspected file
return:true or false if the file is not empty

Examples

*** 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 valueDescription
partsstr, PathnullComponents of the path, e.g. dir, subdir, filename.ext
param parts:Components of the path, e.g. dir, subdir, filename.ext
return:complete file path as a single string

Examples

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

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

Arguments

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

Examples

*** 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 valueDescription
pathstr, Path, NoneNonebase directory for search, defaults to current working directory
param path:base directory for search, defaults to current working directory
return:list of files in directory

Examples

*** 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 valueDescription
pathstr, Path, NoneNonebase directory to start from, defaults to current working dir
param path:base directory to start from, defaults to current working dir

Examples

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

Move a directory from source path to destination path.

Arguments

ArgumentTypeDefault valueDescription
sourcestr, Pathnullsource directory path for moving
destinationstr, Pathnullpath to move to
overwriteboolFalsereplace destination directory if it already exists (defaults to False)
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)

Examples

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

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

Arguments

ArgumentTypeDefault valueDescription
sourcestr, Pathnullsource file path for moving
destinationstr, Pathnullpath to move to
overwriteboolFalsereplace destination file if it already exists (defaults to False)
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)

Examples

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

Move multiple files to the destination folder.

Arguments

ArgumentTypeDefault valueDescription
sourcesList[str | Path]nulllist of files to move
destinationstr, Pathnullpath to move destination
overwriteboolFalsereplace destination files if they already exist
param sources:list of files to move
param destination:
 path to move destination
param overwrite:
 replace destination files if they already exist

Examples

*** 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 valueDescription
pathstr, Pathnullpath that will be normalized
param path:path that will be normalized
return:path to file as a string

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file to read
param path:path to file to read
return:the file content as bytes

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file to read
encodingstrutf-8character encoding of file (default utf-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 valueDescription
pathstr, Pathnullpath to directory
recursiveboolFalseremove all subdirectories and files (default to False)
param path:path to directory
param recursive:
 remove all subdirectories and files (default to False)

Examples

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

Removes the given file.

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to the file to remove
missing_okboolTrueignore non-existent file (defaults to True)
param path:path to the file to remove
param missing_ok:
 ignore non-existent file (defaults to True)

Examples

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

Removes multiple files.

Arguments

ArgumentTypeDefault valueDescription
pathsstr, Pathnullpaths to files to be removed
missing_okboolTrueignore non-existent files (default to True)
param paths:paths to files to be removed
param missing_ok:
 ignore non-existent files (default to True)

Examples

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

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

Arguments

ArgumentTypeDefault valueDescription
pathstr, Pathnullpath to file to inspect
keywordstrnullRobot Framework keyword to execute
argsnullarguments to keyword
param path:path to file to inspect
param keyword:Robot Framework keyword to execute
param args:arguments to keyword

Examples

*** 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 valueDescription
pathstr, Pathnullpath to file which is touched
param path:path to file which is touched

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

Arguments

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

Examples

*** 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 valueDescription
pathstr, Pathnullpath to poll
timeoutint, float5.0time in seconds until keyword fails
param path:path to poll
param timeout:time in seconds until keyword fails
return:path to the modified file as a string

Examples

*** 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 valueDescription
pathstr, Pathnullpath to poll
timeoutint, float5.0time in seconds until keyword fails
param path:path to poll
param timeout:time in seconds until keyword fails