[Vala] Listing directory content with GIO



I've tried to list the files in a directory (not using async
functions). This is what I've got:

var libPath = File.new_for_path("/lib/");
var enumerator =
libPath.enumerate_children(FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
var fileinfo = enumerator.next_file(null);
while(fileinfo != null)
{
        stdout.printf("%s\n", fileinfo.get_name());
        fileinfo = enumerator.next_file(null);
}

Is there an easier way of doing it? I don't like that I have "fileinfo
= enumerator.next_file(null);" two times in my code.

I also found two minor glitches in the doc.
1. At the bottom of the page the constants are over the text on the
right: http://valadoc.org/?pkg=gio-2.0&element=GLib
2. A space is missing before GLib.FileEnumerator:
http://valadoc.org/?pkg=gio-2.0&element=GLib.File.enumerate_children



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