mirror of
https://github.com/godotengine/godot.git
synced 2024-12-09 10:09:20 +08:00
f7f6115f76
- Document a few more properties and methods - Add more information to many classes - Fix lots of typos and gramar mistakes - Use [code] tags for parameters consistently - Use [b] and [i] tags consistently - Put "Warning:" and "Note:" on their own line to be more visible, and make them always bold - Tweak formatting in code examples to be more readable - Use double quotes consistently - Add more links to third-party technologies
197 lines
8.8 KiB
XML
197 lines
8.8 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<class name="Directory" inherits="Reference" category="Core" version="3.2">
|
|
<brief_description>
|
|
Type used to handle the filesystem.
|
|
</brief_description>
|
|
<description>
|
|
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]
|
|
</description>
|
|
<tutorials>
|
|
<link>https://docs.godotengine.org/en/latest/getting_started/step_by_step/filesystem.html</link>
|
|
</tutorials>
|
|
<methods>
|
|
<method name="change_dir">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="todir" type="String">
|
|
</argument>
|
|
<description>
|
|
Changes 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] ([code]OK[/code] or [code]ERR_*[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="copy">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="from" type="String">
|
|
</argument>
|
|
<argument index="1" name="to" type="String">
|
|
</argument>
|
|
<description>
|
|
Copies the [code]from[/code] file to the [code]to[/code] 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] ([code]OK[/code], [code]FAILED[/code] or [code]ERR_*[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="current_is_dir" qualifiers="const">
|
|
<return type="bool">
|
|
</return>
|
|
<description>
|
|
Returns whether the current item processed with the last [method get_next] call is a directory ([code].[/code] and [code]..[/code] are considered directories).
|
|
</description>
|
|
</method>
|
|
<method name="dir_exists">
|
|
<return type="bool">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
|
|
</description>
|
|
</method>
|
|
<method name="file_exists">
|
|
<return type="bool">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
|
|
</description>
|
|
</method>
|
|
<method name="get_current_dir">
|
|
<return type="String">
|
|
</return>
|
|
<description>
|
|
Returns the absolute path to the currently opened directory (e.g. [code]res://folder[/code] or [code]C:\tmp\folder[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="get_current_drive">
|
|
<return type="int">
|
|
</return>
|
|
<description>
|
|
Returns the currently opened directory's drive index. See [method get_drive] to convert returned index to the name of the drive.
|
|
</description>
|
|
</method>
|
|
<method name="get_drive">
|
|
<return type="String">
|
|
</return>
|
|
<argument index="0" name="idx" type="int">
|
|
</argument>
|
|
<description>
|
|
On Windows, returns 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.
|
|
</description>
|
|
</method>
|
|
<method name="get_drive_count">
|
|
<return type="int">
|
|
</return>
|
|
<description>
|
|
On Windows, returns the number of drives (partitions) mounted on the current filesystem. On other platforms, the method returns 0.
|
|
</description>
|
|
</method>
|
|
<method name="get_next">
|
|
<return type="String">
|
|
</return>
|
|
<description>
|
|
Returns 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).
|
|
</description>
|
|
</method>
|
|
<method name="get_space_left">
|
|
<return type="int">
|
|
</return>
|
|
<description>
|
|
On UNIX desktop systems, returns the available space on the current directory's disk. On other platforms, this information is not available and the method returns 0 or -1.
|
|
</description>
|
|
</method>
|
|
<method name="list_dir_begin">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="skip_navigational" type="bool" default="false">
|
|
</argument>
|
|
<argument index="1" name="skip_hidden" type="bool" default="false">
|
|
</argument>
|
|
<description>
|
|
Initializes 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.
|
|
</description>
|
|
</method>
|
|
<method name="list_dir_end">
|
|
<return type="void">
|
|
</return>
|
|
<description>
|
|
Closes the current stream opened with [method list_dir_begin] (whether it has been fully processed with [method get_next] or not does not matter).
|
|
</description>
|
|
</method>
|
|
<method name="make_dir">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Creates 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] ([code]OK[/code], [code]FAILED[/code] or [code]ERR_*[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="make_dir_recursive">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Creates 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.
|
|
Returns one of the error code constants defined in [@GlobalScope] ([code]0K[/code], [code]FAILED[/code] or [code]ERR_*[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="open">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Opens an existing directory of the filesystem. The [code]path[/code] 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] ([code]OK[/code] or [code]ERR_*[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="remove">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="path" type="String">
|
|
</argument>
|
|
<description>
|
|
Deletes 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.
|
|
Returns one of the error code constants defined in [@GlobalScope] ([code]OK[/code] or [code]FAILED[/code]).
|
|
</description>
|
|
</method>
|
|
<method name="rename">
|
|
<return type="int" enum="Error">
|
|
</return>
|
|
<argument index="0" name="from" type="String">
|
|
</argument>
|
|
<argument index="1" name="to" type="String">
|
|
</argument>
|
|
<description>
|
|
Renames (move) the [code]from[/code] file to the [code]to[/code] 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] ([code]OK[/code] or [code]FAILED[/code]).
|
|
</description>
|
|
</method>
|
|
</methods>
|
|
<constants>
|
|
</constants>
|
|
</class>
|