public abstract string? get_basename ()

Gets the base name (the last component of the path) for a given File.

If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) it will return a single directory separator ( and on Windows, possibly a drive letter).

The base name is a byte string (not UTF-8). It has no defined encoding or rules other than it may not contain zero bytes. If you want to use filenames in a user interface you should use the display name that you can get by requesting the g_file_attribute_standard_display_name attribute with query_info .

This call does no blocking I/O.

Example: Get the base name:

public static int main (string[] args) {
// Output: ``my-test.txt``
File file = File.new_for_path ("/foo/bar/baz/my-test.txt");
print ("%s\n", file.get_basename ());
return 0;

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



input File


string containing the File's base name, or null if given File is invalid. The returned string should be freed with g_free when no longer needed.