[misc] add fileUtils.listDirAsync

Request information for a files from the directory asynchronously.
https://bugzilla.gnome.org/show_bug.cgi?id=623708
This commit is contained in:
Maxim Ermilov 2010-10-01 01:08:22 +04:00
parent 734d93087a
commit 4c068c135b
2 changed files with 23 additions and 0 deletions

View File

@ -3,6 +3,7 @@ jsdir = $(pkgdatadir)/js
nobase_dist_js_DATA = \
misc/docInfo.js \
misc/fileUtils.js \
misc/format.js \
misc/gnomeSession.js \
misc/params.js \

22
js/misc/fileUtils.js Normal file
View File

@ -0,0 +1,22 @@
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);
});
}