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

See:




2022 vala-language.org