How to create an empty folder in GDScript

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

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?

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://.

wombatstampede | 2019-02-21 07:40

:bust_in_silhouette: Reply From: RenenerG

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

    

Thank you so much

ToufouMaster | 2019-02-21 00:57