Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Uskazd |
I’m trying to build a save system that requires multiple folders and files (cause I actually want to give users the ability to modify some of them).
A problem I keep running into when trying to find these save folders is that my code also finds “.” and “…” folders which don’t exist.
I tried adding a failsafe which checks if that the map has the Game.json file which contains game parameters using “file_exists”.
var world_location = str(str(saveDir) + str(file_name))
var world_file_location = str(str(world_location) + "/Game.json")
func _checkSaves():
#WORKS
if newDir.open(saveDir) == OK:
newDir.list_dir_begin()
var file_name = newDir.get_next()
while(file_name != ""):
if newDir.current_is_dir():
var check_world_file = Directory.new()
world_location = str(str(saveDir) + str(file_name))
check_world_file.open(world_file_location)
if check_world_file.file_exists(world_file_location):
var dir_name = file_name
gameSaves.push_back(dir_name)
print("Found directory: " + file_name)
file_name = newDir.get_next()
newDir.list_dir_end()
print("Folders: " + str(gameSaves))
The output gives the following result:
Found directory: .
Found directory: ..
Found directory: Alpha 1
Folders: []
While it should be:
Found directory: .
Found directory: ..
Found directory: Alpha 1
Folders: [Alpha 1]
And excluding “if check_world_file.file_exists(world_file_location):” gives me:
Found directory: .
Found directory: ..
Found directory: Alpha 1
Folders: [., .., Alpha 1]