Snippet. Vala. Moving File to Trash Bin

This Vala snippet shows how to move a file to the trash/recycle bin.

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

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

Updated on: 26 Apr 2024