summaryrefslogtreecommitdiff
path: root/doc/classes/Directory.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/Directory.xml')
-rw-r--r--doc/classes/Directory.xml37
1 files changed, 33 insertions, 4 deletions
diff --git a/doc/classes/Directory.xml b/doc/classes/Directory.xml
index bcdadcd970..6a126204c6 100644
--- a/doc/classes/Directory.xml
+++ b/doc/classes/Directory.xml
@@ -7,7 +7,8 @@
Directory type. It is used to manage directories and their content (not restricted to the project folder).
When creating a new [Directory], it must be explicitly opened using [method open] before most methods can be used. However, [method file_exists] and [method dir_exists] can be used without opening a directory. If so, they use a path relative to [code]res://[/code].
Here is an example on how to iterate through the files of a directory:
- [codeblock]
+ [codeblocks]
+ [gdscript]
func dir_contents(path):
var dir = Directory.new()
if dir.open(path) == OK:
@@ -21,7 +22,35 @@
file_name = dir.get_next()
else:
print("An error occurred when trying to access the path.")
- [/codeblock]
+ [/gdscript]
+ [csharp]
+ public void DirContents(string path)
+ {
+ var dir = new Directory();
+ if (dir.Open(path) == Error.Ok)
+ {
+ dir.ListDirBegin();
+ string fileName = dir.GetNext();
+ while (fileName != "")
+ {
+ if (dir.CurrentIsDir())
+ {
+ GD.Print("Found directory: " + fileName);
+ }
+ else
+ {
+ GD.Print("Found file: " + fileName);
+ }
+ fileName = dir.GetNext();
+ }
+ }
+ else
+ {
+ GD.Print("An error occurred when trying to access the path.");
+ }
+ }
+ [/csharp]
+ [/codeblocks]
</description>
<tutorials>
<link title="File system">https://docs.godotengine.org/en/latest/getting_started/step_by_step/filesystem.html</link>
@@ -96,7 +125,7 @@
<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.
+ 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 exist, the method returns an empty String.
</description>
</method>
<method name="get_drive_count">
@@ -138,7 +167,7 @@
<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).
+ Closes the current stream opened with [method list_dir_begin] (whether it has been fully processed with [method get_next] does not matter).
</description>
</method>
<method name="make_dir">