Directory utils for Godot 3.x.
Includes functions for:
- Recursively listing the contents of a directory
- Recursively removing a directory
- Recursively copying a directory
Given a directory located at res://my_dir
like
my_dir
- dir1
- file1
- file2
- dir2
And dir_util.gd
loaded like
const DirUtil = preload("res://addons/dir_util/dir_util.gd")
Returns a Dictionary
of the directory's contents. An empty Dictionary
will be returned
if the directory does not exist.
var files: Dictionary = DirUtil.get_files_recursive("res://my_dir")
print(files.size()) # prints "2"
print(files.dir1.size()) # prints "2"
print(files.dir2.size()) # prints "0"
Expected contents of files
{
"dir1": {
"file1": "res://my_dir/dir1/file1",
"file2": "res://my_dir/dir1/file2",
},
"dir2": {}
}
Returns OK
or an error code.
assert(DirUtils.copy_dir_recursive("res://my_dir", "res://some_other_dir"), OK)
Returns OK
or an error code.
assert(DirUtils.remove_dir_recursive("res://my_dir"), OK)