6

I am developing a Chrome extension and I want to check if a file exists. I don't want to do anything with the file: I only want to check its existence.

If I use a XMLHttpRequest it doesn't work, because it is not allowed for security reasons. So I have to use the HTML5 FS API. The problem is that this API has no method to check if a file exists.

I have a variable called "fileExists", and I would want to know how to change its value from false to true or from true to false depending on the existence of a file (determined by a URL).

Thanks.

1 Answer 1

14

use something like:

   function exists(fileName, callback) {
        storageRootEntry.getFile(fileName, {create : false}, function() {
            callback(true);
        }, function() {
            callback(false);
        });
    }

where storageRootEntry is correctly initialized root directory. The function will returns "true" if file exists and "false" otherwise. The key point here is second parameter {create : false}

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

1 Comment

Thanks for your answer. I'm sorry to add this comment now but the Stackoverflow notification system didn't work properly for me.

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.