Snippet. Vala. Deleting a File

This little snippet shows how to delete a file in Vala.

var file = File.new_for_path("filename.txt");

try {
    if(file.query_exists() == true){
        file.delete();
    }
} catch (Error e) {
    stderr.printf ("Error: %s\n", e.message);
}

Updated on: 23 Nov 2024