How can I get the list of files inside a folder?

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

Suppose there’s a folder in the path of my project (res://) where the user can add scripts (for example res://GameAddons/). How can I get a list of the files in this folder?

This should get you started:

	var dir := DirAccess.open("res://my_folder")
	if dir == null: printerr("Could not open folder"); return
	dir.list_dir_begin()
	for file: String in dir.get_files():
		var resource := load(dir.get_current_dir() + "/" + file)
		print(resource)

Be aware of the Note under DirAccess.get_files() though.

Thank you very much, I read the get_files() documentation, but it’s no problem because I only need the .gd files.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.