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
> [email protected]
> https://mail.gnome.org/mailman/listinfo/vala-list
>
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list