public abstract File set_display_name (string display_name, Cancellable? cancellable = null) throws Error

Renames this to the specified display name.

The display name is converted from UTF-8 to the correct encoding for the target filesystem if possible and the this is renamed to this.

If you want to implement a rename operation in the user interface the edit name ( STANDARD_EDIT_NAME) should be used as the initial value in the rename widget, and then the result after editing should be passed to set_display_name.

On success the resulting converted filename is returned.

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: Rename a file, sync:

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

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

return 0;

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



input File


a string


optional Cancellable object, null to ignore


a File specifying what this was renamed to, or null if there was an error. Free the returned object with unref.