I have an array that contains file names. My code needs to check each file to find out if it needs to be downloaded or it it already exists. The problem is that when I call the resolveLocalFileSystemURL function from the loop, is does not get the correct file name, it always gets the last file name from the array. Any suggestions how to pass the correct file name along with the function call?
var currentFile = "";
for (var i = 0; i < files.length; i++)
{
currentFile = files[i];
window.resolveLocalFileSystemURL(cordova.file.dataDirectory + currentFile , ok, downloadFile);
}
function downloadFile() {
....download currentFile....
}
function ok(entry)
{
...
}
Here is how I managed to solve it (reference: Cordova resolvaLocalFileSystemUrl() cannot async for loop within)
for (var i = 0; i < files.length; i++)
{
(function (i) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory + files[i]
, function(entry){
...ok....
}
, function() {
...download files[i]...
});
})(i);
}