[Vala] [newbie][vala] file_info.get_file_type() is always UNKNOWN



I can't figure out what I'm doing wrong. What I'm trying to do is determine whether a file is a directory or not. But I always get the answer of UNKNOWN (i.e., 0) whether it's a data file or a directory,

// valac --pkg gio-2.0 walker.vala
// ./walker

void  walk (File directory)
{
   try
{ var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0);
      FileInfo file_info;
      while ((file_info = enumerator.next_file ()) != null)
      {  var   type  =  file_info.get_file_type();
         string   d_name   =  file_info.get_name();
         File  f  =  File.new_for_path (d_name);
stdout.printf ("file type = %d\n", type);
         if (type == FileType.DIRECTORY)
         {  walk (f);   }
         else
         {  stdout.printf ("%s\n", f.get_path ()); }
      }
   }
   catch (Error e)
   {  stderr.printf ("Error: %s\n", e.message);
   }
}

int main (string[] args)
{  File  directory;
   if (args.length > 1)
   {  directory = File.new_for_commandline_arg (args[1]);   }
   else
   {  directory = File.new_for_path (".");   }
   walk (directory);
}




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