Dir.make_dir("folder_name") does not work on android

I want to store the images that go trough my app on my phone drive so I can access them both in the app.
These images come from the gallery so they don’t have an import file, and need to be loaded manually, but trying to make a directory so I can call them whenever does not work.

here is a bit of test code I use

var directory_name = ""
	if (OS.get_name() == "Android"):
		directory_name = "/storage/emulated/0/"
		var dir = DirAccess.open(directory_name)
		if (dir.dir_exists("Alarmz")):
        #continue and access the files
		else:
			$test_label.text = "folder does not exist"
            dir.make_dir("Alarmz")

“Alarmz” is not a map in my storage, so it should be made trough this code, but it isn’t.
The text of the label get’s changed correctly, but the folder is not made.
What am I doing incorrect?

Do I need to ask the user for permission to save/create files/folders?
If so how do I do that?

Its probably because the app is sandboxed.
I dont know where the physical directory on Android would be, but wht could help is try using directory_name = "user://" and then printing it out using ProjectSettings.globalize_path() method to get an idea. That is where the data should go.

Also here is this thread. where is the user:// folder located in android?

1 Like