class_diraccess.rst 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/DirAccess.xml.
  6. .. _class_DirAccess:
  7. DirAccess
  8. =========
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Provides methods for managing directories and their content.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class is used to manage directories and their content, even outside of the project folder.
  15. \ **DirAccess** can't be instantiated directly. Instead it is created with a static method that takes a path for which it will be opened.
  16. Most of the methods have a static alternative that can be used without creating a **DirAccess**. Static methods only support absolute paths (including ``res://`` and ``user://``).
  17. ::
  18. # Standard
  19. var dir = DirAccess.open("user://levels")
  20. dir.make_dir("world1")
  21. # Static
  22. DirAccess.make_dir_absolute("user://levels/world1")
  23. \ **Note:** Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. Use :ref:`ResourceLoader<class_ResourceLoader>` to access imported resources.
  24. Here is an example on how to iterate through the files of a directory:
  25. .. tabs::
  26. .. code-tab:: gdscript
  27. func dir_contents(path):
  28. var dir = DirAccess.open(path)
  29. if dir:
  30. dir.list_dir_begin()
  31. var file_name = dir.get_next()
  32. while file_name != "":
  33. if dir.current_is_dir():
  34. print("Found directory: " + file_name)
  35. else:
  36. print("Found file: " + file_name)
  37. file_name = dir.get_next()
  38. else:
  39. print("An error occurred when trying to access the path.")
  40. .. code-tab:: csharp
  41. public void DirContents(string path)
  42. {
  43. using var dir = DirAccess.Open(path);
  44. if (dir != null)
  45. {
  46. dir.ListDirBegin();
  47. string fileName = dir.GetNext();
  48. while (fileName != "")
  49. {
  50. if (dir.CurrentIsDir())
  51. {
  52. GD.Print($"Found directory: {fileName}");
  53. }
  54. else
  55. {
  56. GD.Print($"Found file: {fileName}");
  57. }
  58. fileName = dir.GetNext();
  59. }
  60. }
  61. else
  62. {
  63. GD.Print("An error occurred when trying to access the path.");
  64. }
  65. }
  66. .. rst-class:: classref-introduction-group
  67. Tutorials
  68. ---------
  69. - :doc:`File system <../tutorials/scripting/filesystem>`
  70. .. rst-class:: classref-reftable-group
  71. Properties
  72. ----------
  73. .. table::
  74. :widths: auto
  75. +-------------------------+----------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`include_hidden<class_DirAccess_property_include_hidden>` |
  77. +-------------------------+----------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`include_navigational<class_DirAccess_property_include_navigational>` |
  79. +-------------------------+----------------------------------------------------------------------------+
  80. .. rst-class:: classref-reftable-group
  81. Methods
  82. -------
  83. .. table::
  84. :widths: auto
  85. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`change_dir<class_DirAccess_method_change_dir>` **(** :ref:`String<class_String>` to_dir **)** |
  87. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`copy<class_DirAccess_method_copy>` **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to, :ref:`int<class_int>` chmod_flags=-1 **)** |
  89. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`copy_absolute<class_DirAccess_method_copy_absolute>` **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to, :ref:`int<class_int>` chmod_flags=-1 **)** |static| |
  91. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`bool<class_bool>` | :ref:`current_is_dir<class_DirAccess_method_current_is_dir>` **(** **)** |const| |
  93. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`bool<class_bool>` | :ref:`dir_exists<class_DirAccess_method_dir_exists>` **(** :ref:`String<class_String>` path **)** |
  95. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`bool<class_bool>` | :ref:`dir_exists_absolute<class_DirAccess_method_dir_exists_absolute>` **(** :ref:`String<class_String>` path **)** |static| |
  97. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`file_exists<class_DirAccess_method_file_exists>` **(** :ref:`String<class_String>` path **)** |
  99. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`String<class_String>` | :ref:`get_current_dir<class_DirAccess_method_get_current_dir>` **(** :ref:`bool<class_bool>` include_drive=true **)** |const| |
  101. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`int<class_int>` | :ref:`get_current_drive<class_DirAccess_method_get_current_drive>` **(** **)** |
  103. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories<class_DirAccess_method_get_directories>` **(** **)** |
  105. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories_at<class_DirAccess_method_get_directories_at>` **(** :ref:`String<class_String>` path **)** |static| |
  107. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`int<class_int>` | :ref:`get_drive_count<class_DirAccess_method_get_drive_count>` **(** **)** |static| |
  109. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`String<class_String>` | :ref:`get_drive_name<class_DirAccess_method_get_drive_name>` **(** :ref:`int<class_int>` idx **)** |static| |
  111. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files<class_DirAccess_method_get_files>` **(** **)** |
  113. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files_at<class_DirAccess_method_get_files_at>` **(** :ref:`String<class_String>` path **)** |static| |
  115. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`String<class_String>` | :ref:`get_next<class_DirAccess_method_get_next>` **(** **)** |
  117. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_DirAccess_method_get_open_error>` **(** **)** |static| |
  119. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`int<class_int>` | :ref:`get_space_left<class_DirAccess_method_get_space_left>` **(** **)** |
  121. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>` **(** **)** |
  123. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | void | :ref:`list_dir_end<class_DirAccess_method_list_dir_end>` **(** **)** |
  125. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir<class_DirAccess_method_make_dir>` **(** :ref:`String<class_String>` path **)** |
  127. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_absolute<class_DirAccess_method_make_dir_absolute>` **(** :ref:`String<class_String>` path **)** |static| |
  129. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>` **(** :ref:`String<class_String>` path **)** |
  131. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive_absolute<class_DirAccess_method_make_dir_recursive_absolute>` **(** :ref:`String<class_String>` path **)** |static| |
  133. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`DirAccess<class_DirAccess>` | :ref:`open<class_DirAccess_method_open>` **(** :ref:`String<class_String>` path **)** |static| |
  135. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove<class_DirAccess_method_remove>` **(** :ref:`String<class_String>` path **)** |
  137. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove_absolute<class_DirAccess_method_remove_absolute>` **(** :ref:`String<class_String>` path **)** |static| |
  139. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename<class_DirAccess_method_rename>` **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to **)** |
  141. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename_absolute<class_DirAccess_method_rename_absolute>` **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to **)** |static| |
  143. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. .. rst-class:: classref-section-separator
  145. ----
  146. .. rst-class:: classref-descriptions-group
  147. Property Descriptions
  148. ---------------------
  149. .. _class_DirAccess_property_include_hidden:
  150. .. rst-class:: classref-property
  151. :ref:`bool<class_bool>` **include_hidden**
  152. .. rst-class:: classref-property-setget
  153. - void **set_include_hidden** **(** :ref:`bool<class_bool>` value **)**
  154. - :ref:`bool<class_bool>` **get_include_hidden** **(** **)**
  155. If ``true``, hidden files are included when navigating the directory.
  156. Affects :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>`, :ref:`get_directories<class_DirAccess_method_get_directories>` and :ref:`get_files<class_DirAccess_method_get_files>`.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_DirAccess_property_include_navigational:
  160. .. rst-class:: classref-property
  161. :ref:`bool<class_bool>` **include_navigational**
  162. .. rst-class:: classref-property-setget
  163. - void **set_include_navigational** **(** :ref:`bool<class_bool>` value **)**
  164. - :ref:`bool<class_bool>` **get_include_navigational** **(** **)**
  165. If ``true``, ``.`` and ``..`` are included when navigating the directory.
  166. Affects :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>` and :ref:`get_directories<class_DirAccess_method_get_directories>`.
  167. .. rst-class:: classref-section-separator
  168. ----
  169. .. rst-class:: classref-descriptions-group
  170. Method Descriptions
  171. -------------------
  172. .. _class_DirAccess_method_change_dir:
  173. .. rst-class:: classref-method
  174. :ref:`Error<enum_@GlobalScope_Error>` **change_dir** **(** :ref:`String<class_String>` to_dir **)**
  175. Changes the currently opened directory to the one passed as an argument. The argument can be relative to the current directory (e.g. ``newdir`` or ``../newdir``), or an absolute path (e.g. ``/tmp/newdir`` or ``res://somedir/newdir``).
  176. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_DirAccess_method_copy:
  180. .. rst-class:: classref-method
  181. :ref:`Error<enum_@GlobalScope_Error>` **copy** **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to, :ref:`int<class_int>` chmod_flags=-1 **)**
  182. Copies the ``from`` file to the ``to`` 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.
  183. If ``chmod_flags`` is different than ``-1``, the Unix permissions for the destination path will be set to the provided value, if available on the current operating system.
  184. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. _class_DirAccess_method_copy_absolute:
  188. .. rst-class:: classref-method
  189. :ref:`Error<enum_@GlobalScope_Error>` **copy_absolute** **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to, :ref:`int<class_int>` chmod_flags=-1 **)** |static|
  190. Static version of :ref:`copy<class_DirAccess_method_copy>`. Supports only absolute paths.
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_DirAccess_method_current_is_dir:
  194. .. rst-class:: classref-method
  195. :ref:`bool<class_bool>` **current_is_dir** **(** **)** |const|
  196. Returns whether the current item processed with the last :ref:`get_next<class_DirAccess_method_get_next>` call is a directory (``.`` and ``..`` are considered directories).
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_DirAccess_method_dir_exists:
  200. .. rst-class:: classref-method
  201. :ref:`bool<class_bool>` **dir_exists** **(** :ref:`String<class_String>` path **)**
  202. Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_DirAccess_method_dir_exists_absolute:
  206. .. rst-class:: classref-method
  207. :ref:`bool<class_bool>` **dir_exists_absolute** **(** :ref:`String<class_String>` path **)** |static|
  208. Static version of :ref:`dir_exists<class_DirAccess_method_dir_exists>`. Supports only absolute paths.
  209. .. rst-class:: classref-item-separator
  210. ----
  211. .. _class_DirAccess_method_file_exists:
  212. .. rst-class:: classref-method
  213. :ref:`bool<class_bool>` **file_exists** **(** :ref:`String<class_String>` path **)**
  214. Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
  215. For a static equivalent, use :ref:`FileAccess.file_exists<class_FileAccess_method_file_exists>`.
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_DirAccess_method_get_current_dir:
  219. .. rst-class:: classref-method
  220. :ref:`String<class_String>` **get_current_dir** **(** :ref:`bool<class_bool>` include_drive=true **)** |const|
  221. Returns the absolute path to the currently opened directory (e.g. ``res://folder`` or ``C:\tmp\folder``).
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_DirAccess_method_get_current_drive:
  225. .. rst-class:: classref-method
  226. :ref:`int<class_int>` **get_current_drive** **(** **)**
  227. Returns the currently opened directory's drive index. See :ref:`get_drive_name<class_DirAccess_method_get_drive_name>` to convert returned index to the name of the drive.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_DirAccess_method_get_directories:
  231. .. rst-class:: classref-method
  232. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories** **(** **)**
  233. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files. The array is sorted alphabetically.
  234. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_DirAccess_method_get_directories_at:
  238. .. rst-class:: classref-method
  239. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories_at** **(** :ref:`String<class_String>` path **)** |static|
  240. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files, at the given ``path``. The array is sorted alphabetically.
  241. Use :ref:`get_directories<class_DirAccess_method_get_directories>` if you want more control of what gets included.
  242. .. rst-class:: classref-item-separator
  243. ----
  244. .. _class_DirAccess_method_get_drive_count:
  245. .. rst-class:: classref-method
  246. :ref:`int<class_int>` **get_drive_count** **(** **)** |static|
  247. On Windows, returns the number of drives (partitions) mounted on the current filesystem.
  248. On macOS, returns the number of mounted volumes.
  249. On Linux, returns the number of mounted volumes and GTK 3 bookmarks.
  250. On other platforms, the method returns 0.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_DirAccess_method_get_drive_name:
  254. .. rst-class:: classref-method
  255. :ref:`String<class_String>` **get_drive_name** **(** :ref:`int<class_int>` idx **)** |static|
  256. On Windows, returns the name of the drive (partition) passed as an argument (e.g. ``C:``).
  257. On macOS, returns the path to the mounted volume passed as an argument.
  258. On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
  259. On other platforms, or if the requested drive does not exist, the method returns an empty String.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_DirAccess_method_get_files:
  263. .. rst-class:: classref-method
  264. :ref:`PackedStringArray<class_PackedStringArray>` **get_files** **(** **)**
  265. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories. The array is sorted alphabetically.
  266. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>`.
  267. \ **Note:** When used on a ``res://`` path in an exported project, only the files actually included in the PCK at the given folder level are returned. In practice, this means that since imported resources are stored in a top-level ``.godot/`` folder, only paths to ``*.gd`` and ``*.import`` files are returned (plus a few files such as ``project.godot`` or ``project.binary`` and the project icon). In an exported project, the list of returned files will also vary depending on whether :ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectSettings_property_editor/export/convert_text_resources_to_binary>` is ``true``.
  268. .. rst-class:: classref-item-separator
  269. ----
  270. .. _class_DirAccess_method_get_files_at:
  271. .. rst-class:: classref-method
  272. :ref:`PackedStringArray<class_PackedStringArray>` **get_files_at** **(** :ref:`String<class_String>` path **)** |static|
  273. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories, at the given ``path``. The array is sorted alphabetically.
  274. Use :ref:`get_files<class_DirAccess_method_get_files>` if you want more control of what gets included.
  275. .. rst-class:: classref-item-separator
  276. ----
  277. .. _class_DirAccess_method_get_next:
  278. .. rst-class:: classref-method
  279. :ref:`String<class_String>` **get_next** **(** **)**
  280. Returns the next element (file or directory) in the current directory.
  281. 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 :ref:`String<class_String>` and closes the stream automatically (i.e. :ref:`list_dir_end<class_DirAccess_method_list_dir_end>` would not be mandatory in such a case).
  282. .. rst-class:: classref-item-separator
  283. ----
  284. .. _class_DirAccess_method_get_open_error:
  285. .. rst-class:: classref-method
  286. :ref:`Error<enum_@GlobalScope_Error>` **get_open_error** **(** **)** |static|
  287. Returns the result of the last :ref:`open<class_DirAccess_method_open>` call in the current thread.
  288. .. rst-class:: classref-item-separator
  289. ----
  290. .. _class_DirAccess_method_get_space_left:
  291. .. rst-class:: classref-method
  292. :ref:`int<class_int>` **get_space_left** **(** **)**
  293. Returns the available space on the current directory's disk, in bytes. Returns ``0`` if the platform-specific method to query the available space fails.
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_DirAccess_method_list_dir_begin:
  297. .. rst-class:: classref-method
  298. :ref:`Error<enum_@GlobalScope_Error>` **list_dir_begin** **(** **)**
  299. Initializes the stream used to list all files and directories using the :ref:`get_next<class_DirAccess_method_get_next>` function, closing the currently opened stream if needed. Once the stream has been processed, it should typically be closed with :ref:`list_dir_end<class_DirAccess_method_list_dir_end>`.
  300. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  301. \ **Note:** The order of files and directories returned by this method is not deterministic, and can vary between operating systems. If you want a list of all files or folders sorted alphabetically, use :ref:`get_files<class_DirAccess_method_get_files>` or :ref:`get_directories<class_DirAccess_method_get_directories>`.
  302. .. rst-class:: classref-item-separator
  303. ----
  304. .. _class_DirAccess_method_list_dir_end:
  305. .. rst-class:: classref-method
  306. void **list_dir_end** **(** **)**
  307. Closes the current stream opened with :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>` (whether it has been fully processed with :ref:`get_next<class_DirAccess_method_get_next>` does not matter).
  308. .. rst-class:: classref-item-separator
  309. ----
  310. .. _class_DirAccess_method_make_dir:
  311. .. rst-class:: classref-method
  312. :ref:`Error<enum_@GlobalScope_Error>` **make_dir** **(** :ref:`String<class_String>` path **)**
  313. 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 :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`).
  314. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  315. .. rst-class:: classref-item-separator
  316. ----
  317. .. _class_DirAccess_method_make_dir_absolute:
  318. .. rst-class:: classref-method
  319. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_absolute** **(** :ref:`String<class_String>` path **)** |static|
  320. Static version of :ref:`make_dir<class_DirAccess_method_make_dir>`. Supports only absolute paths.
  321. .. rst-class:: classref-item-separator
  322. ----
  323. .. _class_DirAccess_method_make_dir_recursive:
  324. .. rst-class:: classref-method
  325. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive** **(** :ref:`String<class_String>` path **)**
  326. Creates a target directory and all necessary intermediate directories in its path, by calling :ref:`make_dir<class_DirAccess_method_make_dir>` recursively. The argument can be relative to the current directory, or an absolute path.
  327. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  328. .. rst-class:: classref-item-separator
  329. ----
  330. .. _class_DirAccess_method_make_dir_recursive_absolute:
  331. .. rst-class:: classref-method
  332. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive_absolute** **(** :ref:`String<class_String>` path **)** |static|
  333. Static version of :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`. Supports only absolute paths.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_DirAccess_method_open:
  337. .. rst-class:: classref-method
  338. :ref:`DirAccess<class_DirAccess>` **open** **(** :ref:`String<class_String>` path **)** |static|
  339. Creates a new **DirAccess** object and opens an existing directory of the filesystem. The ``path`` argument can be within the project tree (``res://folder``), the user directory (``user://folder``) or an absolute path of the user filesystem (e.g. ``/tmp/folder`` or ``C:\tmp\folder``).
  340. Returns ``null`` if opening the directory failed. You can use :ref:`get_open_error<class_DirAccess_method_get_open_error>` to check the error that occurred.
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_DirAccess_method_remove:
  344. .. rst-class:: classref-method
  345. :ref:`Error<enum_@GlobalScope_Error>` **remove** **(** :ref:`String<class_String>` path **)**
  346. Permanently 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.
  347. If you don't want to delete the file/directory permanently, use :ref:`OS.move_to_trash<class_OS_method_move_to_trash>` instead.
  348. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  349. .. rst-class:: classref-item-separator
  350. ----
  351. .. _class_DirAccess_method_remove_absolute:
  352. .. rst-class:: classref-method
  353. :ref:`Error<enum_@GlobalScope_Error>` **remove_absolute** **(** :ref:`String<class_String>` path **)** |static|
  354. Static version of :ref:`remove<class_DirAccess_method_remove>`. Supports only absolute paths.
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_DirAccess_method_rename:
  358. .. rst-class:: classref-method
  359. :ref:`Error<enum_@GlobalScope_Error>` **rename** **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to **)**
  360. Renames (move) the ``from`` file or directory to the ``to`` destination. Both arguments should be paths to files or directories, either relative or absolute. If the destination file or directory exists and is not access-protected, it will be overwritten.
  361. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _class_DirAccess_method_rename_absolute:
  365. .. rst-class:: classref-method
  366. :ref:`Error<enum_@GlobalScope_Error>` **rename_absolute** **(** :ref:`String<class_String>` from, :ref:`String<class_String>` to **)** |static|
  367. Static version of :ref:`rename<class_DirAccess_method_rename>`. Supports only absolute paths.
  368. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  369. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  370. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  371. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  372. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  373. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`