[ Version ( since = "2.18" ) ]
public bool make_directory_with_parents (Cancellable? cancellable = null) throws Error

Creates a directory and any parent directories that may not exist similar to 'mkdir -p'.

If the file system does not support creating directories, this function will fail, setting throws to g_io_error_not_supported. If the directory itself already exists, this function will fail setting throws to g_io_error_exists, unlike the similar create_with_parents.

For a local File the newly created directories will have the default (current) ownership and permissions of the current process.

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: Create a directory with parents:

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

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

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



input File


optional Cancellable object, null to ignore


true if all directories have been successfully created, false otherwise.