get_parent


Description:

public abstract File? get_parent ()

Gets the parent directory for the this.

If the this represents the root directory of the file system, then null will be returned.

This call does no blocking I/O.

Example: Get the parent directory:

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

File file = File.new_for_commandline_arg (args[1]);
for (File pos = file; pos != null; pos = pos.get_parent ()) {
print ("%s\n", pos.get_path ());
}

return 0;
}

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

Parameters:

this

input File

Returns:

a File structure to the parent of the given File or null if there is no parent. Free the returned object with unref.




2022 vala-language.org