Re: [Vala] Listing directory content with GIO



Jan Niklas Hasse wrote:
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.

FileInfo fileinfo;
while ((fileinfo = enumerator.next_file(null)) != null)
{
        stdout.printf("%s\n", fileinfo.get_name());
}


Regards,

Frederik



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