Skip to content

Instantly share code, notes, and snippets.

@YeOldeDM
Created August 6, 2016 20:18
Show Gist options
  • Save YeOldeDM/1338f93c98523e5e13596c16b77ac969 to your computer and use it in GitHub Desktop.
Save YeOldeDM/1338f93c98523e5e13596c16b77ac969 to your computer and use it in GitHub Desktop.
delete a folder, and all contents of that folder
func _delete_data(path):
var dir = Directory.new()
var opened = dir.change_dir(path)
if opened != OK:
OS.alert("Error "+str(opened)+" opening path: "+path)
dir.list_dir_begin()
var current = dir.get_next()
print(current)
while not current.empty():
if dir.current_is_dir():
if !current.begins_with('.'):
_delete_data(path+'/'+current)
else:
var removed = dir.remove(path+'/'+current)
if !removed==OK:
OS.alert("Error "+str(removed)+" deleting: "+current)
current = dir.get_next()
var deleted = dir.remove(path)
if !deleted==OK:
OS.alert("Error "+str(deleted)+" deleting: "+path)
return deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment