Topic was automatically imported from the old Question2Answer platform.
Asked By
Mrpaolosarino
I want to make a load scene where every .file is represented in a box. Meaning I want to create a multiple load scene that I can just press and it load. I need to detect if there is .file with any name so I can use it
func get_files_from_directory(path : String, suffix : String = "") -> PoolStringArray:
var list : PoolStringArray = PoolStringArray()
var dir : Directory = Directory.new()
if not dir.dir_exists(path):
push_warning("Path does not exist: " + path)
return list
dir.open(path)
dir.list_dir_begin(true)
var file : String = " "
while file != "":
file = dir.get_next()
if not file:
break # EOD
if dir.current_is_dir():
continue # Just files, no directories
if suffix and not file.ends_with(suffix):
continue # not the correct suffix
list.append(path + file)
return list
It will return an Array with all files that end with ‘.file’ in user:// if you use it like this:
var files : PoolStringArray = get_files_from_directory("user://", ".file")