Skip to main content

Robot Task Activities - File​

The File activities write, read, copy, move, delete, archive and wait for files.

The File category in the activity list, from Write File to Empty Recycle Bin

The activities run in the desktop session of the Robot Task, as the user logged on to that session, so that user needs permission on every path used. Variables are resolved in every path and text field.

Several activities write their outcome to a Result property, in the Properties pane under Output. The value is an RPA variable that exists while the Robot Task runs, used in later activities as {RPA(VariableName)}.


Write File​

Creates the file, writes the text to it, and closes it.

The Write File activity, with the File path and Text fields

  • File path: the full path of the file
  • Text: the text written to the file
warning

If the file already exists, it is replaced without warning.


Append File​

Opens the file, adds the text to its end, and closes it. If the file does not exist, it is created.

  • File path: the full path of the file
  • Text: the text added to the file

No line break is added. To put each entry on its own line, end the text with a line break.

Use Append File rather than Write File when you log progress inside a loop, so that each iteration adds to the log instead of replacing it.


Delete File​

Deletes the file. A file that does not exist is not an error.

  • File path: the full path of the file
warning

The file is deleted permanently. It is not moved to the Recycle Bin and cannot be restored.


Copy File​

Copies a file to a new file. The copy fails if the destination file already exists.

The Copy File activity, with the Source file path and Destination file path fields

  • Source file path: the full path of the file to copy
  • Destination file path: the full path of the new file

Move File​

Moves a file to a new location, optionally with a new name. The move fails if the destination file already exists.

  • Source file path: the full path of the file to move
  • Destination file path: the full path, including the file name, to move it to

File Exists​

Checks whether a file exists and writes the result to the Result variable: "True" if the file exists, and "False" if it does not or the path is a folder.

The File Exists activity, with the File path field

  • File path: the full path of the file to check
  • Result: in the Properties pane, the name of the variable the result is written to

Read the result in a later activity with {RPA(VariableName)}.


Download File​

Downloads a file from a URL.

The Download File activity, with the Url address and File path fields

  • Url address: the URL to download from
  • File path: the full path to save the file to; an existing file is replaced

Read File​

Reads the whole content of a text file and writes it to the Result variable.

  • File path: the full path of the file
  • Result: in the Properties pane, the name of the variable the content is written to

Read the content in a later activity with {RPA(VariableName)}.


Open File​

Opens the file with the application registered for its file type, the same as double-clicking it in File Explorer.

  • File path: the full path of the file

Rename File​

Gives a file a new name in the same folder.

  • File path: the full path of the file
  • New name: the new file name

Touch File​

Creates the file if it does not exist, and sets its last access time to the current time. The last write time is not changed.

  • File path: the full path of the file

Get Files​

Finds the files that match a file filter and runs the Body once for each one, with the full file name. It works like a For Each loop over the matched files.

The Get Files activity, with the File path variable name field, the File filter button and the Body

  • File path variable name: the name of the variable the full file name is written to on each iteration
  • File filter: opens the file filter window, used to choose which files match; see File filter
  • Body: the activities that run for each matched file

Use {RPA(FileName)} in the child activities to get the current file name, with the variable name you set in place of FileName.

A Get Files activity whose Body contains an Open File activity that uses the file name variable

For example, a Get Files activity whose Body contains an Open File activity with the File path {RPA(FileName)} opens every matched file in turn.


Archive - Compress​

Creates a compressed archive of the files that match a file filter.

The Archive - Compress activity, with the File filter button and the Compressed file path field

  • File filter: opens the file filter window, used to choose the files to compress; see File filter
  • Compressed file path: the path of the archive file to create

The archive is always written in 7z format, whatever the file extension.

warning

An existing file at Compressed file path is replaced without warning.


Archive - Extract​

Extracts all files from an archive.

The Archive - Extract activity, with the Source file path and Destination folder path fields

  • Source file path: the archive file to extract
  • Destination folder path: the folder the files are extracted to
warning

Files that already exist in Destination folder path are replaced without warning.


Wait For File​

Waits for a file to exist and writes the result to the Result variable: "True" if the file appears before the time runs out, and "False" if it does not.

The Wait For File activity, with the File path and Wait for file fields and the Throw exception check box

  • File path: the full path of the file to wait for
  • Wait for file: how long to wait, in milliseconds, "10000" by default
  • Throw exception: when checked, which is the default, the activity fails if the file does not appear in time
  • Result: in the Properties pane, the name of the variable the result is written to
warning

With Throw exception cleared, a file that never appears is only written to the output, and the sequence continues. Unless a later activity tests the Result variable, the Task reports success.


Create Shortcut​

Creates a shortcut (.lnk) file. If the destination name does not end in .lnk, the extension is added.

  • Source file path: the file the shortcut points to
  • Destination file path: the path of the shortcut file

The Properties pane has further shortcut settings under Additional, such as the arguments, working directory, icon location and window style.


Empty Recycle Bin​

Empties the Recycle Bin, without asking for confirmation.

warning

This permanently deletes everything in the Recycle Bin on every drive, for the user the Robot Task runs as. Deleted files cannot be restored afterward. If emptying fails, the activity does not report it.


Tips​

  • Use Wait For File rather than a fixed Wait activity when another system produces the file. It continues as soon as the file appears, instead of always waiting the full time
  • Leave Throw exception cleared on Wait For File and test the Result variable with an If (simple) activity when a missing file is a case you want to handle rather than an error
  • Copy File and Move File do not overwrite. If the destination may already exist, use Delete File first, or check with File Exists and branch on the result
  • Use Append File for progress logs inside a loop. Write File replaces the file, so each iteration would discard the earlier entries
  • Combine File Exists with an If (simple) activity to make a Task safe to run again, for example by skipping records whose output file has already been produced