文件计数
动词:countFiles
计算目录中包含的文件数,可以将掩码用作过滤器。
语法
countFiles --path(String) [--filemask(String)] [--alldirectories(Boolean)] [--fileSystem(FileSystem)] (Numeric)=value
输入
| 脚本 | 设计器 | 必需的 | AcceptedTypes | Description |
|---|---|---|---|---|
| --path | 目录路径 | 必需的 | 文本 | 要计算其中文件数的完整目录路径。 |
| --filemask | 掩码 | 可选 | 文本 | 要在搜索中应用的过滤器。 必须按以下方式插入过滤器:[Name or part of the file name, spaces are not accepted in this part]. [File extension]。 下面是一些示例:输入文件名时,必须区分大小写。 |
| --alldirectories | 子文件夹 | 可选 | BOOLEAN | 用于计算指定目录的子目录中文件数的选项。 |
| --fileSystem | 文件系统 | 可选 | 文件系统 | 文件系统的连接变量。1. 要获取具有可用文件系统的连接变量,必须使用以下某个命令建立此连接:IBM RPA 控制中心。 2. 如果未在此参数中指定任何内容,那么将使用操作系统的本地文件系统作为缺省值。 |
输出
| 脚本 | 设计器 | AcceptedTypes | Description |
|---|---|---|---|
| 值 | 数量 | 成员 | 所计算的指定目录中的文件数(该目录在目录路径参数中指定)。 |
示例
使用文件计数命令计算所准备目录中创建的所有文件数,而不使用过滤器掩码。
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