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)});
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.
Confirm your dir
parameter passed to checkFile
. It should end with '/'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With