Type used to handle the filesystem.
Directory type. It is used to manage directories and their content (not restricted to the project folder).
Here is an example on how to iterate through the files of a directory:
[codeblock]
func dir_contents(path):
var dir = Directory.new()
if dir.open(path) == OK:
dir.list_dir_begin()
var file_name = dir.get_next()
while (file_name != ""):
if dir.current_is_dir():
print("Found directory: " + file_name)
else:
print("Found file: " + file_name)
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
[/codeblock]
https://docs.godotengine.org/en/latest/getting_started/step_by_step/filesystem.html
Change the currently opened directory to the one passed as an argument. The argument can be relative to the current directory (e.g. [code]newdir[/code] or [code]../newdir[/code]), or an absolute path (e.g. [code]/tmp/newdir[/code] or [code]res://somedir/newdir[/code]).
The method returns one of the error code constants defined in [@GlobalScope] (OK or ERR_*).
Copy the [i]from[/i] file to the [i]to[/i] destination. Both arguments should be paths to files, either relative or absolute. If the destination file exists and is not access-protected, it will be overwritten.
Returns one of the error code constants defined in [@GlobalScope] (OK, FAILED or ERR_*).
Return whether the current item processed with the last [method get_next] call is a directory ([code].[/code] and [code]..[/code] are considered directories).
Return whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
Return whether the target file exists. The argument can be relative to the current directory, or an absolute path.
Return the absolute path to the currently opened directory (e.g. [code]res://folder[/code] or [code]C:\tmp\folder[/code]).
Returns the currently opened directory's drive index. See [method get_drive] to convert returned index to the name of the drive.
On Windows, return the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]). On other platforms, or if the requested drive does not existed, the method returns an empty String.
On Windows, return the number of drives (partitions) mounted on the current filesystem. On other platforms, the method returns 0.
Return the next element (file or directory) in the current directory (including [code].[/code] and [code]..[/code], unless [code]skip_navigational[/code] was given to [method list_dir_begin]).
The name of the file or directory is returned (and not its full path). Once the stream has been fully processed, the method returns an empty String and closes the stream automatically (i.e. [method list_dir_end] would not be mandatory in such a case).
On Unix desktop systems, return the available space on the current directory's disk. On other platforms, this information is not available and the method returns 0 or -1.
Initialise the stream used to list all files and directories using the [method get_next] function, closing the current opened stream if needed. Once the stream has been processed, it should typically be closed with [method list_dir_end].
If you pass [code]skip_navigational[/code], then [code].[/code] and [code]..[/code] would be filtered out.
If you pass [code]skip_hidden[/code], then hidden files would be filtered out.
Close the current stream opened with [method list_dir_begin] (whether it has been fully processed with [method get_next] or not does not matter).
Create a directory. The argument can be relative to the current directory, or an absolute path. The target directory should be placed in an already existing directory (to create the full path recursively, see [method make_dir_recursive]).
The method returns one of the error code constants defined in [@GlobalScope] (OK, FAILED or ERR_*).
Create a target directory and all necessary intermediate directories in its path, by calling [method make_dir] recursively. The argument can be relative to the current directory, or an absolute path.
Return one of the error code constants defined in [@GlobalScope] (OK, FAILED or ERR_*).
Open an existing directory of the filesystem. The [i]path[/i] argument can be within the project tree ([code]res://folder[/code]), the user directory ([code]user://folder[/code]) or an absolute path of the user filesystem (e.g. [code]/tmp/folder[/code] or [code]C:\tmp\folder[/code]).
The method returns one of the error code constants defined in [@GlobalScope] (OK or ERR_*).
Delete the target file or an empty directory. The argument can be relative to the current directory, or an absolute path. If the target directory is not empty, the operation will fail.
Return one of the error code constants defined in [@GlobalScope] (OK or FAILED).
Rename (move) the [i]from[/i] file to the [i]to[/i] destination. Both arguments should be paths to files, either relative or absolute. If the destination file exists and is not access-protected, it will be overwritten.
Return one of the error code constants defined in [@GlobalScope] (OK or FAILED).