+2 votes

This works inside the godot engine but not when I export the game.
the game has chmod 777

Writing a File works but creating a folder doesn't

OS:Ubuntu
path=/media/name/Volume/newfolder

var d = Directory.new()
if( !d.dir_exists(path) ):
    var err = d.make_dir_recursive(path)
    print(err)

Result:

ERROR: make_dir_recursive: Method/Function Failed, returning: err At: core/os/dir_access.cpp:186.
err=2 

Creating a folder with make_dir(path) also doesn't work.

asked Mar 12, 2016 in Engine by alexholly (172 points)
edited Mar 18, 2016 by Bojidar Marinov

2 Answers

+1 vote
Best answer

I was having this same issue until I had an aha moment.
directory (or d in this case) needs to open the path you want to make the directory at
so..
d.open(path)
you should set the path variable to a directory that exists already and you will be making the new directory in that existing directory.

the reason on a exported game why this does not work is because d's current directory is "res://" which is inside of your executable and not accesible

i hope this helped a bit.

answered Mar 16, 2016 by FlavoredCactus (51 points)
selected Mar 19, 2016 by alexholly
Globals.globalize_path("res://")

Is function worth remembering

0 votes

it should look like this:

var d = Directory.new()
if !(d.dir_exists("user://somedir")):
    print("ERR: dir does not exist ")
    d.open("user://")
    d.make_dir("user://somedir")
answered Apr 15, 2016 by twinpixel (184 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.