Topic was automatically imported from the old Question2Answer platform.
Asked By
Suleymanov
While trying to figure out the easiest way of sorting the best lap times I decided to store the lap times in the name of the files so that they are automatically sorted in an ascending order inside the folder. But how can I call only the first 10 files in the folder?
Hello,
what you are trying to do can be achieved using the following code:
func get_10_files(dir: String) -> Array:
var d := Directory.new()
d.open(dir)
d.list_dir_begin(true, true)
var files := []
for i in 10:
var file_name := d.get_next()
if lap_time == "":
break # there was less than 10 files
files.append(file_name)
return files
However this is a really weird way of doing things. Array have a sort method that sort their content.
A better method would be to store al scores in a single file and work from here rather than relying on your OS sorting file names…