function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
}
function onFileSystemSuccess(fileSystem) {
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("MyDirectory", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail);
}
function onDirectorySuccess(parent) {
var directoryReader = parent.createReader();
directoryReader.readEntries(success, fail);
}
function fail(error) {
alert("Failed to list directory contents: " + error.code);
}
function success(entries) {
if (entries.length == 0)
console.log("No Records");
else
{
for (var i = 0; i < entries.length; i++) {
entries[i].file(function (file) {
console.log("file.name " + file.name);
})
}
}
console.log('file list created');
}
function onDirectoryFail(error) {
alert("Unable to create new directory: " + error.code);
}
function onFileSystemFail(evt) {
console.log(evt.target.error.code);
}
Using the above code, I am getting the list of files. But the problem is in this code is "console.log('file list created')" is executed first and then the "console.log('file.name '+file.name)" are executed. I need to list the file names and then the list created information or I need to know when the list creates completely. Thanks in advance.
Just put the console.log in the if-statement: