Background: I have downloaded and stored some files on my phone. I want to retrieve these files one after another and parse them individually. The results from the parsing are used for further calculations.
Problem: The files are not getting extracted properly. So the parsing is also not happening properly. The code I have so far:
var knownFiles=[];
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fs){
fs.root.getDirectory('Amazedata', null,
function(d){
var dirReader = d.createReader();
dirReader.readEntries(function(entries){
if (!entries.length) {
alert('FileSystem is Empty');
}
else{
for(var i=0; i<entries.length;i++){
knownFiles.push(entries[i].name);
var file = entries[i].fullPath;
//console.log(file);
Papa.parse(file,{
header: true,
dynamicTyping: true,
complete: function(){
var totAmt =0;
for(var i=1;i<=arguments[0].data.length;i++){
if(!arguments[0].data[1][2]){
totAmt += arguments[0].data[i][28];
}
}
var payerObj={
'PayerAccountID' : arguments[0].data[1][1],
'PayerAccountName' : arguments[0].data[1][8],
'TotalAmount' : totAmt
};
payerAccArr.push(payerObj);
$('#loading1').removeClass('show').addClass('hide');
$('#content-Container').removeClass('hide').addClass('show');
},
error: errorFn
});
}
// for(var i=0;i<knownFiles.length;i++){
// }
}
}, onError);
}, onError );
}, onRequestError);
How do I get the file for parsing? What am I missing? The error I am getting is
TypeError: Unable to get reference for 1
I am using Papa.parse for parsing.