Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | axsfew |
Version: Godot 4 beta 10
I am trying to remove a not empty folder (temporary in run time) , but the following code doesn’t work.
func list_files_in_directory(path):
var files = []
var dir = DirAccess.open(path)
dir.list_dir_begin()
while true:
var file = dir.get_next()
if file == "":
break
elif not file.begins_with("."):
files.append(file)
dir.list_dir_end()
return files
func scanall(path):
var debug=[]
var paths=list_files_in_directory(path)
for i in paths:
#print(path+i)
debug+=[path+i]
var DirA =DirAccess.open(path)
if DirA.dir_exists(i+"/"):
debug+=scanall(path+i+"/")
return debug
func _ready():
for i in scanall("res://tmp/"):
DirAccess.remove_absolute(i)
I use first two to get all the file under a folder and I remove them one by one in the ready function, but it seems it’s no use.