Search in sources :

Example 1 with DirectoryNotFoundException

use of com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException in project capacitor-plugins by ionic-team.

the class FilesystemPlugin method readdir.

@PluginMethod
public void readdir(PluginCall call) {
    String path = call.getString("path");
    String directory = getDirectoryParameter(call);
    if (isPublicDirectory(directory) && !isStoragePermissionGranted()) {
        requestAllPermissions(call, "permissionCallback");
    } else {
        try {
            String[] files = implementation.readdir(path, directory);
            if (files != null) {
                JSObject ret = new JSObject();
                ret.put("files", JSArray.from(files));
                call.resolve(ret);
            } else {
                call.reject("Unable to read directory");
            }
        } catch (DirectoryNotFoundException ex) {
            call.reject(ex.getMessage());
        }
    }
}
Also used : DirectoryNotFoundException(com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

DirectoryNotFoundException (com.capacitorjs.plugins.filesystem.exceptions.DirectoryNotFoundException)1 JSObject (com.getcapacitor.JSObject)1 PluginMethod (com.getcapacitor.PluginMethod)1