28 lines
690 B
Vala
28 lines
690 B
Vala
|
void rm_rf (File directory) throws Error {
|
||
|
var children = directory.enumerate_children ("standard::*",
|
||
|
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
||
|
FileInfo fileinfo = null;
|
||
|
while ((fileinfo = children.next_file (null)) != null ) {
|
||
|
File child = directory.resolve_relative_path (fileinfo.get_name ());
|
||
|
if (fileinfo.get_file_type () == FileType.DIRECTORY) {
|
||
|
rm_rf (child);
|
||
|
} else {
|
||
|
print (@"rm $(child.get_path())\n");
|
||
|
child.delete();
|
||
|
}
|
||
|
}
|
||
|
print (@"rmdir $(directory.get_path())\n");
|
||
|
directory.delete();
|
||
|
}
|
||
|
|
||
|
int main () {
|
||
|
try {
|
||
|
rm_rf (File.new_for_path("/tmp/aaa"));
|
||
|
} catch (Error e) {
|
||
|
stderr.puts ("Error: $(e.message)\n");
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|