sanedroid
sanedroid

Reputation: 1036

Ionic checkFile(path,filename) NOT_FOUND_ERR

File Path - file:///data/data/io.ionic.starter/data.json

I wish to check if 'data.json' exists in the mentioned path.

But I recieve an error - {"code":1,"message":"NOT_FOUND_ERR"} Currently the file isn't present in the path so I am expecting the Promise<> to return false, but it ends up throwing an error.

Sample code:

var fileName = "data.json";
     this.file.checkFile(this.file.applicationStorageDirectory, fileName)
    .then((result) => {
    console.log('file exists :' + result);
    },(error){
    console.log('error : ' + JSON.stringify(error)});

Upvotes: 5

Views: 6476

Answers (2)

Hanbing Yin
Hanbing Yin

Reputation: 51

Confirm your dir parameter passed to checkFile. It should end with '/'.

Upvotes: 3

Fernando Paredes
Fernando Paredes

Reputation: 61

I had the same problem with checkDir.

At the end I found the problem. It works a little bit different than expected.

When the directory (or file in your case) exists, then indeed executes the then part. When the directory does not exists then it does not return a false value but instead goes to the error part (catch) with the code 1. So if the error code is 1 it means the file does not exists in the directory.

Upvotes: 6

Related Questions