Get Files Count¶
This operation returns the number of files and optionally directories located in the specified path. Additional options include:
- pattern filtering - counts files and directories which match the pattern.
- recursive counting - when enabled, counts all matching files and directories while recursively traversing the directory structure.
Backendless.Files.getFileCount(path, pattern, sub, countDirectories)
.then((filesCount) => {
console.log('Count: ', filesCount)
})
.catch((error) => {
console.log('Error', error)
})
where:
Argument | Description |
---|---|
path |
String value. A path of a directory in the Backendless files storage starting with / |
pattern |
String value. A pattern which the counted files and optionally directories (if the recursive parameter is set to true ) must match. Backendless supports two formats for pattern: glob and regular expressions. You can specify the pattern matching format to use with a prefix as shown below:glob:profilepic*.png or regex:pic[0-9]\.png . If the prefix format is not specified, Backendless treats the pattern as glob. |
sub |
Boolean value. If set to true , recursively count matching files in all subdirectories. |
countDirectories |
if set to true , count directories in addition to files. |
where:
Argument | Description |
---|---|
path |
Path of a directory in the Backendless files storage starting with / |
pattern |
A pattern which the counted files and optionally directories (if the recursive parameter is set to true ) must match. Backendless supports two formats for pattern: glob and regular expressions. You can specify the pattern matching format to use with a prefix as shown below:glob:profilepic*.png or regex:pic[0-9]\.png . If the prefix format is not specified, Backendless treats the pattern as glob. |
recursive |
If set to true, recursively count matching files in all subdirectories. |
countDirectories |
If set to true, count directories in addition to files. |
Example¶
var path = "web";
var pattern = "*.html";
var recursive = true;
var countDirectories = true;
Backendless.Files.getFileCount( path, pattern, recursive, countDirectories )
.then((filesCount) => {
console.log( 'Found .html files: ', filesCount );
})
.catch((error) => {
});
Codeless Reference¶
where:
Argument | Description |
---|---|
path |
A path identifying a directory where files and folders must be counted. The path must start with the root directory of the remote file storage. |
pattern |
A pattern which the counted files and optionally directories (if the recursive parameter is set to true ) must match. Backendless supports two formats for pattern: glob and regular expressions. You can specify the pattern matching format to use with a prefix as shown below:glob:profilepic*.png or regex:pic[0-9]\.png . If the prefix format is not specified, Backendless treats the pattern as glob. |
recursive |
If set to true , recursively counts files in all subdirectories. |
count directories |
If set to true , counts directories in addition to files. |
Returns the number of files and/or directories in the specified path.
Consider the following files stored in the days
directory:
The example below counts the number of files in the "days"
directory.
The result of this operation will look as shown below after the Codeless logic runs: