5

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)});
2

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.