Quantcast
Channel: Ayyaz Zafar | Freelance Web Developer
Viewing all articles
Browse latest Browse all 28

Cordova: How to check if a file exists or not?

$
0
0

document.addEventListener("deviceready", init, false);

//The directory to store data
var store;

//File name of our important data file we didn't ship with the app
var fileName = "testfile.txt";

function init() {
    
   

    console.log("Checking for data file.");
    // output in android: file:///storage/emulated/0/
    store = cordova.file.externalRootDirectory;
   // or
   // store = "cdvfile://localhost/persistent/";
    //Check for the file. 
    window.resolveLocalFileSystemURL(store + fileName, onSuccess, onFail);

}

function onSuccess() {
   console.log("Great! This file exists");
}

function onFail() {
    console.log('Sorry! File not Found');
}

Above code works for both files and directories.

For Full article with extended features visit Following:
Cordova Sample: Check for a file and download if it isn’t there

Click here for Complete Documentation of cordova.file plugin

 

The post Cordova: How to check if a file exists or not? appeared first on Ayyaz Zafar | Freelance Web Developer.


Viewing all articles
Browse latest Browse all 28

Trending Articles