public abstract bool make_directory (Cancellable? cancellable = null) throws Error

Creates a directory.

Note that this will only create a child directory of the immediate parent directory of the path or URI given by the File. To recursively create directories, see make_directory_with_parents. This function will fail if the parent directory does not exist, setting throws to g_io_error_not_found. If the file system doesn't support creating directories, this function will fail, setting throws to g_io_error_not_supported.

For a local File the newly created directory 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 single directory:

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 ();
} catch (Error e) {
print ("Error: %s\n", e.message);
return 0;

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



input File


optional Cancellable object, null to ignore


true on successful creation, false otherwise.