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?
Update: Works on iOS too.
Try:
function checkIfFileExists(path){
// path is the full absolute path to the file.
window.resolveLocalFileSystemURL(path, fileExists, fileDoesNotExist);
}
function fileExists(fileEntry){
alert("File " + fileEntry.fullPath + " exists!");
}
function fileDoesNotExist(){
alert("file does not exist");
}
Found the solution here.
Works on Android. Will test on iOS and update this answer.
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