+3 votes

How to create an empty folder in GDScript?

var file = File.new()
file.open("res://SaveFiles/Save1", File.WRITE)
file.store_line(str(Lvl))
file.close()

SaveFiles Folder is not created
i want to create It

but How?

in Engine by (14 points)

Important:
Do not write to res://

Write to user:// instead. This is the intended path where user data should go. (naturally, with exceptions always possible)

res:// is not guaranteed to have write rights. This varies on operating system and install method but especially the mobile platforms won't allow writing to res://.

1 Answer

+1 vote

Hello ToufouMaster,

How to create an empty folder in GDScript?

You can create easily an empty folder by passing the path, something like this should create just an empty folder:

func _ready( ):
    # Creates an empty folder.
    var directory = Directory.new( )
    directory.make_dir("res://SaveFiles")

    # Then you could create for example a new file like you already do with:
    var file = File.new( )
    # Note here the file extension ".txt"
    file.open("res://SaveFiles/save1.txt", File.WRITE)
    file.store_line(str(Lvl))
    file.close

Note here, that you specify in your path what format your file should have. You missed an extension here! Try to extend your path with ".txt" or another format you want.

see make_dir and the descrpition of File for more information

by (250 points)
edited by

Thank you so much

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.
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 webmaster@godotengine.org with your username.