A library providing keywords for operating system related tasks.

OperatingSystem is Robot Framework's standard library that enables various operating system related tasks to be performed in the system where Robot Framework is running. It can, among other things, execute commands (e.g. Run), create and remove files and directories (e.g. Create File, Remove Directory), check whether files or directories exists or contain something (e.g. File Should Exist, Directory Should Be Empty) and manipulate environment variables (e.g. Set Environment Variable).

Table of contents

Path separators

Because Robot Framework uses the backslash (\) as an escape character in its data, using a literal backslash requires duplicating it like in c:\\path\\file.txt. That can be inconvenient especially with longer Windows paths, and thus all keywords expecting paths as arguments convert forward slashes to backslashes automatically on Windows. This also means that paths like ${CURDIR}/path/file.txt are operating system independent.

Notice that the automatic path separator conversion does not work if the path is only a part of an argument like with the Run keyword. In these cases the built-in variable ${/} that contains \ or /, depending on the operating system, can be used instead.

Pattern matching

Many keywords accepts arguments as either glob or regular expression patterns.

Glob patterns

Some keywords, for example List Directory, support so called glob patterns where:

*matches any string, even an empty string
?matches any single character
[chars]matches one character in the bracket
[!chars]matches one character not in the bracket
[a-z]matches one character from the range in the bracket
[!a-z]matches one character not from the range in the bracket

Unless otherwise noted, matching is case-insensitive on case-insensitive operating systems such as Windows.

Regular expressions

Some keywords, for example Grep File, support regular expressions that are more powerful but also more complicated that glob patterns. The regular expression support is implemented using Python's re module and its documentation should be consulted for more information about the syntax.

Because the backslash character (\) is an escape character in Robot Framework data, possible backslash characters in regular expressions need to be escaped with another backslash like \\d\\w+. Strings that may contain special characters but should be handled as literal strings, can be escaped with the Regexp Escape keyword from the BuiltIn library.

Tilde expansion

Paths beginning with ~ or ~username are expanded to the current or specified user's home directory, respectively. The resulting path is operating system dependent, but typically e.g. ~/robot is expanded to C:\Users\<user>\robot on Windows and /home/<user>/robot on Unixes.

Boolean arguments

Some keywords accept arguments that are handled as Boolean values true or false. If such an argument is given as a string, it is considered false if it is an empty string or equal to FALSE, NONE, NO, OFF or 0, case-insensitively. Other strings are considered true regardless their value, and other argument types are tested using the same rules as in Python.

True examples:

Remove Directory${path}recursive=True# Strings are generally true.
Remove Directory${path}recursive=yes# Same as the above.
Remove Directory${path}recursive=${TRUE}# Python True is true.
Remove Directory${path}recursive=${42}# Numbers other than 0 are true.

False examples:

Remove Directory${path}recursive=False# String false is false.
Remove Directory${path}recursive=no# Also string no is false.
Remove Directory${path}recursive=${EMPTY}# Empty string is false.
Remove Directory${path}recursive=${FALSE}# Python False is false.


*** Settings *** Library OperatingSystem *** Variables *** ${PATH} ${CURDIR}/example.txt *** Test Cases *** Example Create File ${PATH} Some text File Should Exist ${PATH} Copy File ${PATH} ~/file.txt