Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)});
like image 744
sanedroid Avatar asked Jul 06 '17 06:07

sanedroid


2 Answers

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.

like image 93
Fernando Paredes Avatar answered Nov 09 '22 08:11

Fernando Paredes


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

like image 26
Hanbing Yin Avatar answered Nov 09 '22 07:11

Hanbing Yin