Create a folder using a Godot .exe

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MangoTree

Hi,

I have tried creating a folder (using GDscript) in the same directory as the exported Godot executable, however, I can’t get it to work. I’ve used things like

var dir=Directory.new()
dir.make_dir("res://test")

but that only works using the Godot editor and NOT the final executable. I’ve also tried changing res:// to user://, but that doesn’t work either. Any clues as to how achieve this?

Thanks

you first have to open the base directory that you want to create a new one in:

dir.open("user://")
dir.make_dir("test")

Edit: actually that’s not true. just tested on mac and using dir.make_dir('user://test') works fine. Do you see an error?

Eric Ellingson | 2019-07-12 22:10

Hey, thanks. I ran dir.make_dir('user://test') in the the exported .exe (on Windows), but it’s still not creating a physical folder in the same directory (as the .exe file). I’m running Windows 8.1, so maybe it works on Windows 10.

I found a temporary workaround though: Specifying the absolute path to a directory (e.g. saving to Desktop) works fine, e.g. (“C:/Users/user/Desktop/test”).

MangoTree | 2019-07-13 00:08

:bust_in_silhouette: Reply From: Dlean Jeans

This works:

var dir = Directory.new()
var path = OS.get_executable_path().get_base_dir().plus_file(folder_name)
dir.make_dir(path)

res:// refers to the project root folder in which files and folders can only be created while running the project, can be used by tool scripts and addons.

user:// is the folder opened by Project > Open Project Data folder, which is not the same as the exported Godot game directory mentioned in the question.

Cool, thanks a lot!

MangoTree | 2019-07-13 14:13

Oh my god this was so useful, i had been looking for a solution for hours!

Lorenzo_774 | 2021-10-10 17:36