const Gio = imports.gi.Gio; const GLib = imports.gi.GLib; function listDirAsync(file, callback) { let allFiles = []; file.enumerate_children_async(Gio.FILE_ATTRIBUTE_STANDARD_NAME, Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_LOW, null, function (obj, res) { let enumerator = obj.enumerate_children_finish(res); function onNextFileComplete(obj, res) { let files = obj.next_files_finish(res); if (files.length) { allFiles = allFiles.concat(files); enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); } else { enumerator.close(null); callback(allFiles); } } enumerator.next_files_async(100, GLib.PRIORITY_LOW, null, onNextFileComplete); }); }