namespace Usm.Util { public static void delete_tree(string path) throws Error { // Creating a new Directory object for the given folder path var folder = File.new_for_path(path); // Getting a list of all files and folders inside the directory var enumerator = folder.enumerate_children("*", FileQueryInfoFlags.NONE); // Looping through each file/folder and removing them while (true) { FileInfo? info = enumerator.next_file(); if (info == null) { break; } // Checking if the current item is a file or a folder if (info.get_file_type() == FileType.REGULAR) { // Removing the file var file = folder.get_child(info.get_name()); file.delete(); } else if (info.get_file_type() == FileType.DIRECTORY) { // Removing the folder recursively var subfolder = folder.get_child(info.get_name()); delete_tree(subfolder.get_path()); } } folder.delete(); } public static void unarchive(string archive, string destination) throws Error { var dest = File.new_for_path(destination); if(!dest.query_exists()) { dest.make_directory(); } var proc = new Subprocess.newv(new string[] { "tar", "-xf", archive, "-C", destination }, SubprocessFlags.INHERIT_FDS); if(!proc.wait_check()) { throw new IOError.FAILED(@"Could not extract \"$archive\": tar returned non-zero exit status $(proc.get_status())"); } } public static void archive(string source, string archive) throws Error { var proc = new Subprocess.newv(new string[] { "tar", "-cJf", archive, "--directory", source, "." }, SubprocessFlags.INHERIT_FDS); if(!proc.wait_check()) { throw new IOError.FAILED(@"Could not archive \"$source\": tar returned non-zero exit status $(proc.get_status())"); } } }