Get Files

Gets the file paths that exist in a directory, and can also get file paths from subdirectories of that directory, returning those paths in a list.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

getFiles --path(String) [--recursive(Boolean)] [--filemask(String)] [--orderbyname(Boolean)] [--orderbylastmodification(Boolean)] [--orderbyextension(Boolean)] [--orderbysize(Boolean)] [--reverseordering(Boolean)] [--fileSystem(FileSystem)] (List<String>)=value [--ignorecase](Boolean)

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Directory path Required Text Full path to the directory from which the file paths should be obtained.
Search in Subdirectories recursive Optional Boolean Enable it to search files within subdirectories of the specified directory in the Directory parameter.
File Mask filemask Optional Text Filter to apply in the search. Some examples on how you must use the file mask:

*.txt: filters all files with the ".txt" extension.
name: filters all files that have the word "name" as part of the name.

The file mask is case sensitive. Use the Ignore Case parameter to make the file mask case insensitive.
Order by Name orderbyname Optional Boolean Sorts the files by name.
Order by Last Modification orderbylastmodification Optional Boolean Sorts the files by modification date.
Order by Extension orderbyextension Optional Boolean Sorts files by extension.
Order by Size orderbysize Optional Boolean Sorts the files by size.
Reverse Ordering reverseordering Optional Boolean Reverses the list's sorting.
File System filesystem Optional File Sytem Connection with a file system. For more information about the supported file systems and how to connect to them, see Integration with external apps.

If this parameter is blank, the command uses the operating system's file system.
Ignore Case ignorecase Optional Boolean Enable it to search for files regarding the capitalization of the letters in the file name or in the file extension.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Paths value List<Text> Returns a list containing the file paths found.

Example

Example 1: The command returns the list of file paths from the My Documents folder.

defVar --name filePaths --type List --innertype String
defVar --name myDocumentsFolder --type String
// Gets the path of the My Documents folder
getSpecialFolder --folder "MyDocuments" myDocumentsFolder=value
// Get the files from the My Documents folder
getFiles --path "${myDocumentsFolder}" --orderbyname  filePaths=value
logMessage --message "${filePaths}" --type "Info"

Example 2: The command returns the list of file paths from the My Documents folder, filtering the files by the mask .txt.

defVar --name filePaths --type List --innertype String
defVar --name myDocumentsFolder --type String
// Gets the path of the My Documents folder
getSpecialFolder --folder "MyDocuments" myDocumentsFolder=value
// Get the .txt files from the My Documents folder
getFiles --path "${myDocumentsFolder}" --filemask "*.txt" --orderbyname  filePaths=value
logMessage --message "${filePaths}" --type "Info"

Example 3: The command returns the list of file paths from the My Documents folder which contains .png and .PNG files, filtering the files by the mask .PNG. Despite filtering only .PNG files, due to the ignorecase parameter, the command will return all the files.

defVar --name filePaths --type List --innertype String
defVar --name myDocumentsFolder --type String
// Gets the path of the My Documents folder
getSpecialFolder --folder "MyDocuments" myDocumentsFolder=value
// Get the .PNG files from the My Documents folder
getFiles --path "${myDocumentsFolder}" --filemask "*.PNG" --ignorecase  --orderbyname  filePaths=value
logMessage --message "${filePaths}" --type "Info"
// The result returns files with `.png` and `.PNG` format

Example 4: The command returns the list of file paths from the Passports folder in a Google Drive account.

Before you run this example, you must create a connection to Google Drive named "Google Drive connection". For more information about how to create connections, see Adding connections to an application.

defVar --name googleDriveConnection --type FileSystem
defVar --name filePaths --type List --innertype String
// Connects to a Google Drive account to get files from there
googleDriveConnect --name google_drive_connection_google_drive googleDriveConnection=value
// Get the files from the Passports folder in Google Drive
getFiles --path "/Passports" --orderbyname  --fileSystem ${googleDriveConnection} filePaths=value
logMessage --message "${filePaths}" --type "Info"