mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
167 lines
8.8 KiB
ReStructuredText
167 lines
8.8 KiB
ReStructuredText
.. _class_Directory:
|
|
|
|
Directory
|
|
=========
|
|
|
|
**Inherits:** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
|
|
|
|
**Category:** Core
|
|
|
|
Brief Description
|
|
-----------------
|
|
|
|
Type used to handle the filesystem.
|
|
|
|
Member Functions
|
|
----------------
|
|
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`open<class_Directory_open>` **(** :ref:`String<class_string>` path **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`list_dir_begin<class_Directory_list_dir_begin>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_string>` | :ref:`get_next<class_Directory_get_next>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`current_is_dir<class_Directory_current_is_dir>` **(** **)** const |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| void | :ref:`list_dir_end<class_Directory_list_dir_end>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_drive_count<class_Directory_get_drive_count>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_string>` | :ref:`get_drive<class_Directory_get_drive>` **(** :ref:`int<class_int>` idx **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`change_dir<class_Directory_change_dir>` **(** :ref:`String<class_string>` todir **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`String<class_string>` | :ref:`get_current_dir<class_Directory_get_current_dir>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`make_dir<class_Directory_make_dir>` **(** :ref:`String<class_string>` name **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`make_dir_recursive<class_Directory_make_dir_recursive>` **(** :ref:`String<class_string>` name **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`file_exists<class_Directory_file_exists>` **(** :ref:`String<class_string>` name **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`dir_exists<class_Directory_dir_exists>` **(** :ref:`String<class_string>` name **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_space_left<class_Directory_get_space_left>` **(** **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`copy<class_Directory_copy>` **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`rename<class_Directory_rename>` **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
| Error | :ref:`remove<class_Directory_remove>` **(** :ref:`String<class_string>` file **)** |
|
|
+------------------------------+----------------------------------------------------------------------------------------------------------------------+
|
|
|
|
Description
|
|
-----------
|
|
|
|
Directory type. Is used to manage directories and their content (not restricted to the project folder).
|
|
|
|
Example for how to iterate through the files of a directory:
|
|
|
|
::
|
|
|
|
func dir(path):
|
|
var d = Directory.new()
|
|
if d.open( path )==0:
|
|
d.list_dir_begin()
|
|
var file_name = d.get_next()
|
|
while(file_name!=""):
|
|
if d.current_is_dir():
|
|
print("Found directory: " + file_name)
|
|
else:
|
|
print("Found file:" + file_name)
|
|
file_name = d.get_next()
|
|
else:
|
|
print("Some open Error, maybe directory not found?")
|
|
|
|
Member Function Description
|
|
---------------------------
|
|
|
|
.. _class_Directory_open:
|
|
|
|
- Error **open** **(** :ref:`String<class_string>` path **)**
|
|
|
|
Opens a directory to work with. Needs a path, example "res://folder"
|
|
|
|
.. _class_Directory_list_dir_begin:
|
|
|
|
- :ref:`bool<class_bool>` **list_dir_begin** **(** **)**
|
|
|
|
Loads all file names of the current directory (prepares the get_next() function).
|
|
|
|
.. _class_Directory_get_next:
|
|
|
|
- :ref:`String<class_string>` **get_next** **(** **)**
|
|
|
|
Is used to iterate through the files of the current directory. Returns the name(no path) of the current file/directory, it also contains "." and ".." .
|
|
|
|
Returns an empty String "" at the end of the list.
|
|
|
|
.. _class_Directory_current_is_dir:
|
|
|
|
- :ref:`bool<class_bool>` **current_is_dir** **(** **)** const
|
|
|
|
Returns true if the current file you are looking at with get_next() is a directory or "." or ".." otherwise false.
|
|
|
|
.. _class_Directory_list_dir_end:
|
|
|
|
- void **list_dir_end** **(** **)**
|
|
|
|
Run this to empty the list of remaining files in get_next(). You can use it to end the iteration, as soon as your goal is reached.
|
|
|
|
.. _class_Directory_get_drive_count:
|
|
|
|
- :ref:`int<class_int>` **get_drive_count** **(** **)**
|
|
|
|
.. _class_Directory_get_drive:
|
|
|
|
- :ref:`String<class_string>` **get_drive** **(** :ref:`int<class_int>` idx **)**
|
|
|
|
.. _class_Directory_change_dir:
|
|
|
|
- Error **change_dir** **(** :ref:`String<class_string>` todir **)**
|
|
|
|
Needs a path or name to the next directory. When the target directory is in the current directory you can use "newfolder" otherwise you need the full path "res://currentfolder/newfolder"
|
|
|
|
.. _class_Directory_get_current_dir:
|
|
|
|
- :ref:`String<class_string>` **get_current_dir** **(** **)**
|
|
|
|
Returns a path to the current directory, example: "res://folder"
|
|
|
|
.. _class_Directory_make_dir:
|
|
|
|
- Error **make_dir** **(** :ref:`String<class_string>` name **)**
|
|
|
|
.. _class_Directory_make_dir_recursive:
|
|
|
|
- Error **make_dir_recursive** **(** :ref:`String<class_string>` name **)**
|
|
|
|
.. _class_Directory_file_exists:
|
|
|
|
- :ref:`bool<class_bool>` **file_exists** **(** :ref:`String<class_string>` name **)**
|
|
|
|
.. _class_Directory_dir_exists:
|
|
|
|
- :ref:`bool<class_bool>` **dir_exists** **(** :ref:`String<class_string>` name **)**
|
|
|
|
Returns true if directory exists otherwise false. Needs a path, example: "res://folder"
|
|
|
|
.. _class_Directory_get_space_left:
|
|
|
|
- :ref:`int<class_int>` **get_space_left** **(** **)**
|
|
|
|
.. _class_Directory_copy:
|
|
|
|
- Error **copy** **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)**
|
|
|
|
.. _class_Directory_rename:
|
|
|
|
- Error **rename** **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)**
|
|
|
|
.. _class_Directory_remove:
|
|
|
|
- Error **remove** **(** :ref:`String<class_string>` file **)**
|
|
|
|
|