Can't rename directories

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

I am trying to move a folder from res:// to user:// using the following code:

var dir = Directory.new()

dir.rename("res://dir_name", "user://dir_name")
if dir.open("user://dir_name") == OK:
	print("ok")
else:
    print("not existing")

Output:

not existing

Have you tried adding a leading slash (“/”) to the directory names? Something like this?

dir.rename("res://dir_name/", "user://dir_name/")

Otherwise, this could be a function that’s only related to files (though this functionally is based upon a Unix environment). Have you also tried detecting the directory after trying to move it, e.g.

if not dir.dir_exists("user://dir_name"):
    push_error("Directory doesn't exist")

If all else fails, try copying the directory:

dir.copy("res://dir_name", "user://dir_name")

You could then remove the old directory, though that’s a bit harder, as the remove() function will only delete empty directories.

Ertain | 2021-04-08 19:30

:bust_in_silhouette: Reply From: exuin

res:// directory is not modifiable during runtime

But what’s about modding then? How to make sure no mod overwrites another?

Spyrex | 2021-04-08 19:59

If you want to support modding, I’d try to stick with files in the user:// space and load/read/parse those instead. Mods breaking each other is something you’r enever able to fully avoid. If people can screw up some way, they’ll find it sooner or later. This even hits big AAA games like Skyrim. Just make organizing mods as convenient as possible and if there are conflicts you can detect, warn the user, plus potentially avoid loading the conflicting mod.

Mario | 2021-04-08 23:01

But I have the mod files to be downloaded by Godot.
And Godot always downloads the files into the root of the res://-folder.
What should I do now? There isn’t even the possibility to copy
the folder to the user://-directory.

Spyrex | 2021-04-09 09:41

To be fair, I haven’t tried this myself yet, but you should be able to download a file and do whatever with it without writing it first. Have a look at the example in this answer.

Mario | 2021-04-09 12:40

Oh sorry that was not true.
Godot does not download the files in the res:// folder,
it imports the resources in there. And after that,
I cant move them inside this “res” directory.

Spyrex | 2021-04-09 17:35