Skip to content

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.
- (void)getFileCountWithResponseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;

- (void)getFileCountWithPath:(NSString * _Nonnull)path responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;

- (void)getFileCountWithPath:(NSString * _Nonnull)path pattern:(NSString * _Nonnull)pattern responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;

- (void)getFileCountWithPath:(NSString * _Nonnull)path pattern:(NSString * _Nonnull)pattern recursive:(BOOL)recursive responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;

- (void)getFileCountWithPath:(NSString * _Nonnull)path pattern:(NSString * _Nonnull)pattern recursive:(BOOL)recursive countDirectories:(BOOL)countDirectories responseHandler:^(NSNumber * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func getFileCount(responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

func getFileCount(path: String, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

func getFileCount(path: String, pattern: String, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

func getFileCount(path: String, pattern: String, recursive: Bool, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

func getFileCount(path: String, pattern: String, recursive: Bool, countDirectories: Bool, responseHandler: ((NSNumber) -> Void)!, errorHandler: ((Fault) -> Void)!)

where:

Argument                Description
path path of a directory in the Backendless files storage starting with /
pattern a glob pattern to match files which should be counted.
recursive if set to true, recursively count matching files in all subdirectories.
countDirectories if set to true, count directories in addition to files.

Example

[Backendless.shared.file getFileCountWithPath:@"web" pattern:@"*html" recursive:YES countDirectories:YES responseHandler:^(NSNumber *filesCount) {
    NSLog(@"Files count = %@", filesCount);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
}];
Backendless.shared.file.getFileCount(path: "web", pattern: "*html", recursive: true, countDirectories: true, responseHandler: { filesCount in
    print("Files count = \(filesCount)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")
})