trash


Description:

public abstract bool trash (Cancellable? cancellable = null) throws Error

Sends this to the "Trashcan", if possible.

This is similar to deleting it, but the user can recover it before emptying the trashcan. Not all file systems support trashing, so this call can return the g_io_error_not_supported error. Since GLib 2.66, the `x-gvfs-notrash` unix mount option can be used to disable trash support for certain mounts, the g_io_error_not_supported error will be returned in that case.

If cancellable is not null, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error g_io_error_cancelled will be returned.

Example: Trash a file:

public static int main (string[] args) {
if (args.length != 2) {
print ("%s FILE\n", args[0]);
return 0;
}

try {
File file = File.new_for_commandline_arg (args[1]);
file.trash ();
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}

valac --pkg gio-2.0 GLib.File.trash.vala

Parameters:

this

File to send to trash

cancellable

optional Cancellable object, null to ignore

Returns:

true on successful trash, false otherwise.