File System Action

The File System Action step helps you perform operations on files, directories, and other items using either the direct file access or via Robot File System (RFS). The step offers operations on three levels:

  • Device level actions have no context and fully controlled by parameters.
  • Application level actions operate on directory level, where each directory is represented by an application.
  • Component level actions operate on a file or directory represented by an <item> node in the device tree.

The available commands function identically on any level they occur and differ in the number of parameters.

To enable file system access, including access to the local file system in the Local Desktop Automation mode, select the Allow File System and Command Line Access option on the Security tab in the RoboServer Settings application.

If your RoboServer is configured to forbid local file system access, the robot can run, but it produces an error if the step uses File Access set to Direct Access on the local device. However, the step can work on the local device with File Access set to Via RFS. On a remote device, both "Direct Access" and "Via RFS" can be used at all times.

Applications and Directories

The robot uses the List Directory action to open an application that contains <item> nodes for each object in the directory and some core properties of that object. The application is static and does not update the content of the directory when it changes. To update the contents, your robot can either close the application and reopen it, or use the Refresh action to re-scan the directory contents.

The List Directory action opens a new application. The action provides a required Application Name parameter to set the name attribute on the application.

Assign different application names to applications in a robot to avoid errors.

Error handling

If an error occurs in any action, it produces a DeviceIssue exception. These errors can be caught using the Try-Catch step. You can use the Get Last Error action to retrieve an error reported by the last action performed by the file system driver.

Actions and properties

Action
  • List Directory: Opens a new application representing the contents of the directory. Note that this action can take a significant amount of time to complete.

    Specify File Access, Directory, and Application Name parameters.

  • Delete File: Removes a file.

    Specify File Access and File parameters.

  • Create Directory: Creates a directory with the specified name. This action uses the create directory semantics of the underlying storage.

    Specify File Access and Directory parameters.

  • Delete Directory: Removes a directory. Depending on the underlying storage this action can fail if the directory is not empty.

    Specify File Access and Directory parameters.

  • Exists: Tests if an object exists and returns the result as a boolean.

    Specify File Access and Item parameters, as well as a variable to store the result in the Result field.

  • Copy File: Copies a file to a new location and can be used to copy files between RFS (Robot File System) and the local file system. The source and destination parameters must include the name of the file. This action uses the copy semantics of underlying storage.

    Specify both Source and Destination parameters using paths with file names as well as File Access.

    If you want to copy the file c:\a\b\c.txt into the directory d:\destination, the Source field must contain c:\a\b\c.txt and the Destination field must contain d:\destination\c.txt. If you omit the file name in the Destination field or the destination directory does not exist, the results may be unpredictable.

  • Move: Moves or Renames an object. The source and destination parameters must include the name of the object. This action can not be used to move objects between RFS (Robot File System) and the local file system. The implementation uses the move semantics of the underlying storage.

    Specify File Access as well as Source and Destination parameters using paths with object names.

  • Rename: Renames an object in its current location.

    Specify File Access, Item, and New Name parameters.

  • Get Type: Retrieves the type of an object. Throws a DeviceIssue exception if the object does not exist. This action can return the following values:

    • file: Object is a file.

    • directory: Object is a directory.

    • other: Object exists, but it is not a file or directory. The exact type of object depends on the underlying storage but it can be other objects, such as devices or symbolic links.

    Specify File Access and Item parameters, as well as a variable to store the result in the Type field.

  • Get Path: Retrieves the path to the item.

  • Close All Directories: Closes all applications associated with directories opened by the robot.

  • Close Directory: Closes the application.

  • Count: Counts the number of objects matching the component finder. This action can be used for existence checks and wildcard searches.

  • Get Last Error: Retrieves an error message from the last action performed by the file system driver.

    Specify a variable to store the result in the Error field.

  • Refresh: Scans and reloads the directory contents represented by the application and updates the tree.

    Note that this action can take a significant amount of time to complete.

Properties
  • File Access: Select either Direct Access or Via RFS.

  • Directory: Specify the directory path and name.

  • File: Specify the file path and name.

  • Item: Specify the item's path and name.

  • Application Name: Set the name attribute on the application.

  • Results: Specify a variable to store the results of the action.

Directory elements tree

Each directory opened with the List Directory action is represented by an application with its own tree. The elements in this tree and their values are not localized unless explicitly noted otherwise. The tree has the following structure.

fs element

Element

Description

title

attribute; Title of the application. This is set to the path of the directory.

driver

attribute; Fixed: "fs".

name

attribute; Name of the application. This attribute is set by the List Directory action or generated when the name parameter is omitted.

directory

element; Represents the directory.

directory element

Element

Description

path

attribute; Contains the path used in the List Directory action.

count

attribute; Number of objects in the directory.

item

element, repeating; each item element represents an object in the directory. The order of these elements is not defined and can change after the Refresh action.

item element

This element contains the following node elements.

Element

Description

name

attribute; Name of the object.

size

attribute; Size of the object in bytes as reported by the underlying storage.

extension

attribute; The extension of the object if it is a file converted to lower case. Empty for directories.

type

attribute; Type of the file. Either file for a file, directory for a directory, or other for all other types of objects.

created

attribute; The time when the object was created as reported by the underlying storage. This value is represented as local time in ISO 8601 notation.

modified

attribute; The time when the object was last modified as reported by the underlying storage. This value is represented as local time in ISO 8601 notation.