How to create a new directory?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DimitriyPS
:warning: Old Version Published before Godot 3 was released.

I want to “user://” to create a new directory. I see document: link

I can’t find a method that would create a new directory. If possible, please show a minimal code example.

:bust_in_silhouette: Reply From: eaglecat
func _ready():
	var dir = Directory.new()
	dir.open("user://")
	dir.make_dir("sad")

It works.

Not working for me. As is should make a sad directory in user://

star pirate | 2021-10-23 18:00

:bust_in_silhouette: Reply From: Ninfur

For anyone finding this in Godot 4.0

var dir_access = DirAccess.new()
dir_access.open("user://")
dir_access.make_dir("New Folder")

or, even simpler

DirAccess.make_dir_absolute("user://New Folder/")

Hi there. When I try to use DirAcces.new()
I get an error saying:

Line 13:Native class “DirAccess” cannot be constructed as it is abstract.Line 13:Static function “new()” not found in base “DirAccess”.

Cyber-Kun | 2023-03-31 14:04

I’m guessing the new() call was once necessary, but it isn’t anymore. It should look like this:

var dir = DirAccess.open("user://")
dir.make_dir("New Folder")

Odjur | 2023-04-13 04:41

you could also use:

DirAccess.make_dir_absolute("user://path/to/your/directory")

Cyber-Kun | 2023-04-14 07:09