Re: Getting list of files in a directory with GLib



On Thu, May 10, 2012 at 11:24 PM, Jasper St. Pierre
<jstpierre mecheye net> wrote:
> You want to use Gio.File nowadays. See listDirAsync in:
>    http://git.gnome.org/browse/gnome-shell/tree/js/misc/fileUtils.js

Thanks! I've sort of got it working.
How do I handle the whole asynchronous thing? My current code looks like:

let fileList = [];
let dir = Gio.file_new_for_path( '/path/to/the/directory' );
fileUtils.listDirAsync( dir,
                              function( fileinfos ) {
                                  fileList = fileinfos;
                              } );

If I perform this in the gnome looking glass, it works. When I do it
from gjs (whether the console or script), fileList is empty.

I assume I have to somehow wait for listDirAsync to finish its
business, or perhaps there is some scope problem? How can I simply get
the list of file infos found into fileList? (In the end I just want an
array of string paths).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]