Can't get files from a Directory without breakpoints

Godot Version



I’m trying to get stuff from a Directory with the following GDScript:

func find_folders(path) -> void:
	var ret: Array = []
	var dir =
	if == OK:
		stdprint("Begun search @ " + path)
		var file_name = dir.get_next()
		while file_name != "":
			if dir.current_is_dir():
				stdprint("Found folder: " + file_name)
				ret.append(path + file_name)
			file_name = dir.get_next()
		stderr("An error occurred when trying to access the path.")
	available_folders = ret

but it halts my program indefinitely. That is unless I put breakpoints when calling the function or inside it.
I’ve tried removing dir.make_dir_recursive(path) to see if that was halting the function(previous to trying breakpointing everything) and it didn’t change a thing.
stdprint and stderr are functions that call print and printerr while also printing the text into a RichTextLabel, removing those doesn’t change things.
Any ideas on what may be causing this behavior and/or how to fix it?
Thanks in advance.

Best I can tell it’s your continuing the loop when you hit a file but not advancing the file_name as you don’t call file_name = dir.get_next() so it’s getting stuck.

Try also assigning dir.get_next() to file_name before calling continue or better remove the inner else block completely.

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