[Vala] deleting folders

2012-09-21 Thread D.H. Bahr
Hello everyone!

GLib.File provides a 'delete' method to delete files and empty folders.

I need to delete a non empty folder so I thought of a recursive method
like this:

bool remove_directory (string path) {
  bool flag = false;
  var directory = File.new_for_path (path);
  
  var enumerator = directory.enumerate_children (
FileAttribute.STANDARD_NAME, 0
  );
  
  FileInfo file_info;
  while ((file_info = enumerator.next_file ()) != null) {
if ((file_info.get_file_type ()) == FileType.DIRECTORY) {
  /*
What should I do here? 
How can I get a File from a FileInfo so I can use the 
'delete' method on it?
  */
}
  }
  return flag;
}


Best regards,

D.H. Bahr


10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS...
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION

http://www.uci.cu
http://www.facebook.com/universidad.uci
http://www.flickr.com/photos/universidad_uci
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] deleting folders

2012-09-21 Thread Victor Eduardo
You obviously can't, but you can do the following:

string file_name = file_info.get_name ();
var file = directory.get_child (file_name);

And after that, you can call file.delete().

Regards,
Victor.

On vie, sep 21, 2012 at 1:07 , D.H. Bahr db...@uci.cu wrote:
Hello everyone! 

GLib.File provides a 'delete' method to delete files and empty folders. 

I need to delete a non empty folder so I thought of a recursive method 
like this: 

bool remove_directory (string path) { 
bool flag = false; 
var directory = File.new_for_path (path); 

var enumerator = directory.enumerate_children ( 
FileAttribute.STANDARD_NAME, 0 
); 

FileInfo file_info; 
while ((file_info = enumerator.next_file ()) != null) { 
if ((file_info.get_file_type ()) == FileType.DIRECTORY) { 
/* 
What should I do here? 
How can I get a File from a FileInfo so I can use the 
'delete' method on it? 
*/ 
} 
} 
return flag; 
} 


Best regards, 

D.H. Bahr 


10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS... 
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION 

http://www.uci.cu 
http://www.facebook.com/universidad.uci 
http://www.flickr.com/photos/universidad_uci 
___ 
vala-list mailing list 
vala-list@gnome.org 
https://mail.gnome.org/mailman/listinfo/vala-list 

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] deleting folders

2012-09-21 Thread Victor Eduardo
My last message was incomplete. I meant that you can't get a GLib.File directly 
from a GLib.FileInfo object, but you can do it using the way I suggested.

Hope this helps.

On vie, sep 21, 2012 at 1:07 , D.H. Bahr db...@uci.cu wrote:
Hello everyone! 

GLib.File provides a 'delete' method to delete files and empty folders. 

I need to delete a non empty folder so I thought of a recursive method 
like this: 

bool remove_directory (string path) { 
bool flag = false; 
var directory = File.new_for_path (path); 

var enumerator = directory.enumerate_children ( 
FileAttribute.STANDARD_NAME, 0 
); 

FileInfo file_info; 
while ((file_info = enumerator.next_file ()) != null) { 
if ((file_info.get_file_type ()) == FileType.DIRECTORY) { 
/* 
What should I do here? 
How can I get a File from a FileInfo so I can use the 
'delete' method on it? 
*/ 
} 
} 
return flag; 
} 


Best regards, 

D.H. Bahr 


10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
INFORMATICAS... 
CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION 

http://www.uci.cu 
http://www.facebook.com/universidad.uci 
http://www.flickr.com/photos/universidad_uci 
___ 
vala-list mailing list 
vala-list@gnome.org 
https://mail.gnome.org/mailman/listinfo/vala-list 

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] deleting folders

2012-09-21 Thread Thomas Jollans
On 09/21/2012 09:07 PM, D.H. Bahr wrote:
 Hello everyone!
 
 GLib.File provides a 'delete' method to delete files and empty folders.
 
 I need to delete a non empty folder so I thought of a recursive method
 like this:
 
 bool remove_directory (string path) {
   bool flag = false;
   var directory = File.new_for_path (path);
   
   var enumerator = directory.enumerate_children (
 FileAttribute.STANDARD_NAME, 0
   );
   
   FileInfo file_info;
   while ((file_info = enumerator.next_file ()) != null) {
 if ((file_info.get_file_type ()) == FileType.DIRECTORY) {
   /*
 What should I do here? 
 How can I get a File from a FileInfo so I can use the 
 'delete' method on it?
   */
 }
   }
   return flag;
 }

Hi,

Victor has already given you the answer - you have to use the parent
directory's get_child method.

If you want, you can consult my Emperor file manager's deletion code
at
https://github.com/tjol/emperor/blob/master/src/modules/basic_actions/basic_actions.vala#L256

As this is a GUI file manager, the code is more complex - it uses
asynchronous methods, asks the user for confirmation, and does error
handling. The core loop, equivalent to what you've been writing, is
here:
https://github.com/tjol/emperor/blob/master/src/modules/basic_actions/basic_actions.vala#L348


Code license: GPLv3+

-- Thomas

 
 
 Best regards,
 
 D.H. Bahr
 
 
 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS 
 INFORMATICAS...
 CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION
 
 http://www.uci.cu
 http://www.facebook.com/universidad.uci
 http://www.flickr.com/photos/universidad_uci
 ___
 vala-list mailing list
 vala-list@gnome.org
 https://mail.gnome.org/mailman/listinfo/vala-list
 

___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list