File System Action

Use the File System Action step to perform operations on files, directories, and other items using either direct file access or Robot File System (RFS).

The step offers operations on three levels:

  • Device level actions have no context and are fully controlled by parameters.
  • Application level actions operate on the 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 but 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 works on a local device with File Access set to Via RFS. On a remote device, both Direct Access and Via RFS can run.

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.

  • Opening and closing the applications is done asynchronously. Robots that open and close directories should wait for operations to complete or use application names to avoid finding a previous 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.

Use the Get Last Error action to retrieve an error reported by the last action performed by the file system driver.

Actions and properties

Actions
  • List Directory: Opens a new application representing the contents of the directory. 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. 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, and a variable to store the result in the Result field.

  • Lock Status: Performs a test for read/write locks on Windows files, and returns a numerical status indicator. Lock Status is not available on RFS and Linux.

    • 1 File exists and is not locked.

    • 0 File exists and is locked (reading and writing).

    • -1 File does not exist.

    • -2 Feature is not supported.

    • -3 Failed for another reason. (Use Get Last Error step to retrieve the underlying error.)

  • Copy File: Copies a file to a new location. Also use to copy files between RFS and the local file system. The source and destination parameters must include the name of the file. This action uses the copy semantics of the underlying storage.

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

    If you 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 and the local file system. The implementation uses the move semantics of the underlying storage.

    Specify File Access, 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 returns the following values:

    • file Object is a file.

    • directory Object is a directory.

    • other Object exists, yet 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, and 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 performs 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, then updates the tree. 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 tree

Each directory opened with the List Directory action is represented by an application with its own tree.

A tree has the following structure.

<fs title=”…” driver=”…” name=”…”>
    <directory path=”…” count=”…”>
        <item name=”…” size=”…” extension=”…” type=”…” created=”…” modified=”….”>
        <item name=”…” size=”…” extension=”…” type=”…” created=”…” modified=”….”>
        <item name=”…” size=”…” extension=”…” type=”…” created=”…” modified=”….”>
        ….

The following tables define the nodes (also known as elements), attributes, and child elements in the tree.

fs Node

Description

Type

title

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

attribute

driver

Fixed: fs.

attribute

name

Name of the application.

This attribute is set by the List Directory action.

attribute

directory

Represents the directory.

child element

directory Node

Description

Type

path

Contains the path used in the List Directory action.

attribute

count

Number of objects in the directory.

attribute

item

Each item element represents an object in the directory.

The order of these elements is not defined and can change after the Refresh action.

repeating child element

item Node

Description

Type

name

Name of the object.

attribute

size

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

attribute

extension

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

attribute

type

file, directory, or other.

attribute

created

The time when the object was created, as reported by the underlying storage.

This value is represented as local time in ISO 8601 notation.

attribute

modified

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.

attribute