This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

What is the difference in Godot 2.1.4 (sadly not 3.0) in Directory class open() and change_dir() methods?

in Engine by (111 points)

Think of it like this.

If you click a folder on your desktop,
a new window opens and you see inside the folder.

If you click a folder inside that window,
you change the directory to look at another one.

1 Answer

+2 votes
Best answer

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 =
if"user://") == OK: 
   if dir.change_dir("./xyz") == OK:
       print("You have now descended into the xyz sub directory")
by (270 points)
selected by

Good answer!

Verified that code works ( in Godot 2.1.4 )

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
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
to create a folder named "xyz" inside the current directory.

Or you can use an absolute path :

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.