I never tried it myself, but according to the documentation I understand that first you need to open a directory.
Once it is open, you can use change_dir to point it elsewhere if you wish.
For example
var dir = Directory.new()
if dir.open("user://") == OK:
if dir.change_dir("./xyz") == OK:
print("You have now descended into the xyz sub directory")
Adding a little more for reference in case anyone needs it.
--------------------------------------------------------------------------------------
One dot (".") or ("./") refers to the current directory.
Two dots ("..") or ("../") refers to the parent directory.
When changing a directory, you can use my_dir.change_dir("../") or my_dir.change_dir("..")
to change to the parent directory
Above dir.change_dir("./xyz")
looks in the current directory for a folder named “xyz”,
and returns OK if it’s able to change to that directory.
If it had said instead dir.change_dir("../xyz")
it would look up to the parent directory of where you are
then look inside the parent for a folder named “xyz”.
Quick warning :
I just tried to make a directory in Godot 2.1.4
and you cannot use ./ to do this: my_dir.make_dir(“./xyz”) will NOT work.
Instead you must use my_dir.make_dir("xyz")
to create a folder named “xyz” inside the current directory.
Or you can use an absolute path : my_dir.make_dir("user://xyz")