How to get the first ten files in the folder? (windows)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

:bust_in_silhouette: Reply From: Lola

what you are trying to do can be achieved using the following code:

func get_10_files(dir: String) -> Array:
	var d :=
	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
	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…