Get File 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.
// NON-BLOCKING METHODS public void getFileCount(String path, AsyncCallback<Integer> responder); public void getFileCount(String path, String pattern, AsyncCallback<Integer> responder); public void getFileCount(String path, String pattern, boolean recursive, AsyncCallback<Integer> responder); public void getFileCount(String path, String pattern, boolean recursive, boolean countDirectories, AsyncCallback<Integer> responder); // BLOCKING METHODS public int getFileCount(String path); public int getFileCount(String path, String pattern); public int getFileCount(String path, String pattern, boolean recursive); public int getFileCount(String path, String pattern, boolean recursive, boolean countDirectories);
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¶
String path = "web"; String pattern = "*.html"; boolean recursive = true; boolean countDirectories = true; Backendless.Files.getFileCount( path, pattern, recursive, countDirectories, new AsyncCallback<Integer>() { @Override public void handleResponse( Integer response ) { int fileCount = response; } @Override public void handleFault( BackendlessFault fault ) { } } );