Count Files
Verb: countFiles
Counts the number of files contained in a directory, and a mask can be used as a filter.
Syntax
countFiles --path(String) [--filemask(String)] [--alldirectories(Boolean)] [--fileSystem(FileSystem)] (Numeric)=value
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--path | Directory Path | Required | Text | Full directory path in which files should be counted. |
--filemask | Mask | Optional | Text | Filter that will be applied in the search. It must be inserted as follows: [Name or part of the file name, spaces are not accepted in this part]. [File extension]. Here are some examples:
When entering the name of the file, it must be case sensitive. |
--alldirectories | Subfolders | Optional | Boolean | Option to count files from within subdirectories of specified directory. |
--fileSystem | File System | Optional | File System | Connection variable to a file system.
1. To obtain the connection variable with an available file system, this connection must be established using one of the following commands: IBM RPA Control Center. 2. If nothing is specified in this parameter, the local file system of the operating system is used as default. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Quantity | Number | Number of files counted within the directory given in the Directory Path parameter. |
Example
The Count Files command is used to count all files created within the prepared directory without filter masks.
defVar --name documentsPath --type String
defVar --name filesFolder --type String
defVar --name counter --type Numeric
defVar --name filesQuantity --type Numeric
getSpecialFolder --folder "MyDocuments" documentsPath=value
// Create the folder where files will be added and counted.
createDir --path "${documentsPath}\\countFilesExample" filesFolder=value
for --variable ${counter} --from 0 --to 10 --step 1
writeToFile --value "This is the file: ${counter}" --file "${filesFolder}\\file${counter}.txt"
next
// Count the number of files in the folder.
countFiles --path "${filesFolder}" --alldirectories filesQuantity=value
logMessage --message "The number of files is: ${filesQuantity}" --type "Info"
// After script execution, the result is:
// The number of files is: 11