If the statement from the past question that fileEntry.file () is asynchronous is true, then the task changes.
Since it is unlikely to arrange the further processing in the callback function (as far as I understand you want to send information on all files in one request), the second option remains:
Write a separate function that will check whether all the answers to the sent requests came and only after that will it process the received data. Add a counter that will count the number of sent and received data (when sending a request, we increase the counter by 1, when receiving the data we decrease). If the counter is non-zero, then not all the data has yet come.
An example in a hurry. You can already work in this direction to achieve the desired result.
var p=[], k=0; //объявляем счетчик и массив для данных function readFile(fileEntry){ fileEntry.file(function(file){ p.push('Name: '+file.name+ //пушим данные в массив для дальнейшей обработки 'Last Modified: '+new Date(file.lastModifiedDate)+ 'Size: '+file.size); k--; //понижаем счетчик (данные записались) sendResults(); // вызываем функцию для обработки данных }); } function listResults(entries) { entries.forEach(function(entry) { if (entry.isDirectory) { //.... } else { k++; //увеличиваем счетчик (данные запросили) readFile(entry); } }); } function sendResults(){ //функция для отправки данных if(k==0){ //если счетчик 0, значит полученных ответов столько же сколько отправленных запросов. Можно готовить данные к отправке console.log(p.join('|')); } }
PS I apologize too fast. I still have to check the total number of files I think. As if the first readFile (entry); will work very quickly (before the next one goes to forEach ()), then the sending function will work with the data part.