Count Files

Verb: countFiles

Counts the number of files contained in a directory, and a mask can be used as a filter.


countFiles --path(String) [--filemask(String)] [--alldirectories(Boolean)] [--fileSystem(FileSystem)] (Numeric)=value


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:
  • * .txt: filters all files with the ".txt" extension;
  • name: filters all files that have the word "name" as part of the name.

  • 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.


    Script Designer AcceptedTypes Description
    value Quantity Number Number of files counted within the directory given in the Directory Path parameter.


    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"
    // 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

    See Also

  • Check If Directory Exists
  • Convert Base64 to File
  • Convert File to Base64
  • Copy File
  • Create Directory
  • Delete Directory
  • Delete File
  • Delete from Directory
  • Download from File System
  • Get Directories
  • Get Files
  • If File Exists
  • Move File
  • Read All Bytes
  • Read All Text
  • Rename File
  • Send to File System
  • Write to File