Satch3000 Satch3000 - 2 years ago 302
Javascript Question

Cordova check if file in url exists

I am using cordova / phonegap and need to know if a file exists

Here's the code with the path and filename:

storeUrl = cordova.file.dataDirectory+'myfolder/myfile.mp3';

How can I check if this file exists?

Answer Source

Try code from this link: Code:

function checkIfFileExists(path){
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
        fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);
    }, getFSFail); //of requestFileSystem
function fileExists(fileEntry){
    alert("File " + fileEntry.fullPath + " exists!");
function fileDoesNotExist(){
    alert("file does not exist");
function getFSFail(evt) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download