Ionic Native Checking Directory Error

im trying out some ionic native plugins, so far everything has been great excpet for the file plugin. I’ve been trying to create directory in the externalDataDirectory path provided by the file plugin. What am trying to do is check if the directory exists first but that actually seems to be the issue. I keep getting and ErrCode 5: ENCONDING ERR. Here is my code.

import { File } from '@ionic-native/file';
import { FilePath } from '@ionic-native/file-path';

export class MyClass {

    constructor(private file: File, private filePath: FilePath) {}

    createDirectory(onSuccess?: (val: any) => any, onError?: (err: any) => any) {
    // root_dir = this.file.externalDataDirectory
    this.filePath.resolveNativePath(this.root_dir).then(
      (nativePath) => {
        this.file.checkDir(nativePath, 'myDir').then(
          (exists) => {
            if (!exists) {
              this.file.createDir(nativePath, 'myDir', false).then(
                (dirEntry) => {
                  onSuccess(dirEntry);
                },
                (err) => {
                  console.log('CreateDir error: ' + err);
                  onError(err);
                }
              ).catch( (exception) => { console.log(exception); } );
            }
            else {
              return nativePath + 'myDir';
            }
          },
          (err) => {
            console.log('CheckDir error: ' + err);
            onError(err);
          }
        ).catch( (exception) => { console.log(exception); } );
      },
      (err) => {
       // error occurs here.
        onError(err);
      }
    )
  }
}

I dont know what im doing wrong, can anyone be of assistance. Thanks!!!
I know the problem seem to be from the resolveNativePath method but when I remove that it still doesn’t work I get an error: NOT FOUND

1 Like