get_basename


Description:

public string get_basename (string file_name)

Gets the last component of the filename.

If file_name ends with a directory separator it gets the component before the last slash. If file_name consists only of directory separators (and on Windows, possibly a drive letter), a single separator is returned. If file_name is empty, it gets ".".

Example: Get the basename:

public static int main (string[] args) {
// Output: ``path.txt``
string res = Path.get_basename ("/my/absolute/path.txt");
print ("%s\n", res);

// Output: ``path.txt``
res = Path.get_basename ("../my/absolute/path.txt");
print ("%s\n", res);

return 0;
}

valac --pkg glib-2.0 GLib.Path.get_basename.vala

Parameters:

file_name

the name of the file

Returns:

a newly allocated string containing the last component of the filename


Namespace: GLib.Path
Package: glib-2.0