class_diraccess.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. :github_url: hide
  2. .. meta::
  3. :keywords: directory, path, folder
  4. .. DO NOT EDIT THIS FILE!!!
  5. .. Generated automatically from Godot engine sources.
  6. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/DirAccess.xml.
  8. .. _class_DirAccess:
  9. DirAccess
  10. =========
  11. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  12. Provides methods for managing directories and their content.
  13. .. rst-class:: classref-introduction-group
  14. Description
  15. -----------
  16. This class is used to manage directories and their content, even outside of the project folder.
  17. \ **DirAccess** can't be instantiated directly. Instead it is created with a static method that takes a path for which it will be opened.
  18. 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://``).
  19. ::
  20. # Standard
  21. var dir = DirAccess.open("user://levels")
  22. dir.make_dir("world1")
  23. # Static
  24. DirAccess.make_dir_absolute("user://levels/world1")
  25. \ **Note:** Accessing project ("res://") directories once exported may behave unexpectedly as some files are converted to engine-specific formats and their original source files may not be present in the expected PCK package. Because of this, to access resources in an exported project, it is recommended to use :ref:`ResourceLoader<class_ResourceLoader>` instead of :ref:`FileAccess<class_FileAccess>`.
  26. Here is an example on how to iterate through the files of a directory:
  27. .. tabs::
  28. .. code-tab:: gdscript
  29. func dir_contents(path):
  30. var dir = DirAccess.open(path)
  31. if dir:
  32. dir.list_dir_begin()
  33. var file_name = dir.get_next()
  34. while file_name != "":
  35. if dir.current_is_dir():
  36. print("Found directory: " + file_name)
  37. else:
  38. print("Found file: " + file_name)
  39. file_name = dir.get_next()
  40. else:
  41. print("An error occurred when trying to access the path.")
  42. .. code-tab:: csharp
  43. public void DirContents(string path)
  44. {
  45. using var dir = DirAccess.Open(path);
  46. if (dir != null)
  47. {
  48. dir.ListDirBegin();
  49. string fileName = dir.GetNext();
  50. while (fileName != "")
  51. {
  52. if (dir.CurrentIsDir())
  53. {
  54. GD.Print($"Found directory: {fileName}");
  55. }
  56. else
  57. {
  58. GD.Print($"Found file: {fileName}");
  59. }
  60. fileName = dir.GetNext();
  61. }
  62. }
  63. else
  64. {
  65. GD.Print("An error occurred when trying to access the path.");
  66. }
  67. }
  68. Keep in mind that file names may change or be remapped after export. If you want to see the actual resource file list as it appears in the editor, use :ref:`ResourceLoader.list_directory<class_ResourceLoader_method_list_directory>` instead.
  69. .. rst-class:: classref-introduction-group
  70. Tutorials
  71. ---------
  72. - :doc:`File system <../tutorials/scripting/filesystem>`
  73. .. rst-class:: classref-reftable-group
  74. Properties
  75. ----------
  76. .. table::
  77. :widths: auto
  78. +-------------------------+----------------------------------------------------------------------------+
  79. | :ref:`bool<class_bool>` | :ref:`include_hidden<class_DirAccess_property_include_hidden>` |
  80. +-------------------------+----------------------------------------------------------------------------+
  81. | :ref:`bool<class_bool>` | :ref:`include_navigational<class_DirAccess_property_include_navigational>` |
  82. +-------------------------+----------------------------------------------------------------------------+
  83. .. rst-class:: classref-reftable-group
  84. Methods
  85. -------
  86. .. table::
  87. :widths: auto
  88. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`change_dir<class_DirAccess_method_change_dir>`\ (\ to_dir\: :ref:`String<class_String>`\ ) |
  90. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`copy<class_DirAccess_method_copy>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`, chmod_flags\: :ref:`int<class_int>` = -1\ ) |
  92. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`copy_absolute<class_DirAccess_method_copy_absolute>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`, chmod_flags\: :ref:`int<class_int>` = -1\ ) |static| |
  94. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`create_link<class_DirAccess_method_create_link>`\ (\ source\: :ref:`String<class_String>`, target\: :ref:`String<class_String>`\ ) |
  96. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`bool<class_bool>` | :ref:`current_is_dir<class_DirAccess_method_current_is_dir>`\ (\ ) |const| |
  98. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`dir_exists<class_DirAccess_method_dir_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |
  100. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`bool<class_bool>` | :ref:`dir_exists_absolute<class_DirAccess_method_dir_exists_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  102. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`file_exists<class_DirAccess_method_file_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |
  104. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`String<class_String>` | :ref:`get_current_dir<class_DirAccess_method_get_current_dir>`\ (\ include_drive\: :ref:`bool<class_bool>` = true\ ) |const| |
  106. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`int<class_int>` | :ref:`get_current_drive<class_DirAccess_method_get_current_drive>`\ (\ ) |
  108. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories<class_DirAccess_method_get_directories>`\ (\ ) |
  110. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories_at<class_DirAccess_method_get_directories_at>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  112. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`int<class_int>` | :ref:`get_drive_count<class_DirAccess_method_get_drive_count>`\ (\ ) |static| |
  114. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`String<class_String>` | :ref:`get_drive_name<class_DirAccess_method_get_drive_name>`\ (\ idx\: :ref:`int<class_int>`\ ) |static| |
  116. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files<class_DirAccess_method_get_files>`\ (\ ) |
  118. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files_at<class_DirAccess_method_get_files_at>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  120. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`String<class_String>` | :ref:`get_next<class_DirAccess_method_get_next>`\ (\ ) |
  122. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_DirAccess_method_get_open_error>`\ (\ ) |static| |
  124. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`int<class_int>` | :ref:`get_space_left<class_DirAccess_method_get_space_left>`\ (\ ) |
  126. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`bool<class_bool>` | :ref:`is_case_sensitive<class_DirAccess_method_is_case_sensitive>`\ (\ path\: :ref:`String<class_String>`\ ) |const| |
  128. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`bool<class_bool>` | :ref:`is_link<class_DirAccess_method_is_link>`\ (\ path\: :ref:`String<class_String>`\ ) |
  130. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>`\ (\ ) |
  132. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | |void| | :ref:`list_dir_end<class_DirAccess_method_list_dir_end>`\ (\ ) |
  134. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir<class_DirAccess_method_make_dir>`\ (\ path\: :ref:`String<class_String>`\ ) |
  136. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_absolute<class_DirAccess_method_make_dir_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  138. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`\ (\ path\: :ref:`String<class_String>`\ ) |
  140. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive_absolute<class_DirAccess_method_make_dir_recursive_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  142. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | :ref:`DirAccess<class_DirAccess>` | :ref:`open<class_DirAccess_method_open>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  144. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. | :ref:`String<class_String>` | :ref:`read_link<class_DirAccess_method_read_link>`\ (\ path\: :ref:`String<class_String>`\ ) |
  146. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  147. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove<class_DirAccess_method_remove>`\ (\ path\: :ref:`String<class_String>`\ ) |
  148. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  149. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove_absolute<class_DirAccess_method_remove_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  150. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  151. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename<class_DirAccess_method_rename>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |
  152. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  153. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename_absolute<class_DirAccess_method_rename_absolute>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |static| |
  154. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  155. .. rst-class:: classref-section-separator
  156. ----
  157. .. rst-class:: classref-descriptions-group
  158. Property Descriptions
  159. ---------------------
  160. .. _class_DirAccess_property_include_hidden:
  161. .. rst-class:: classref-property
  162. :ref:`bool<class_bool>` **include_hidden** :ref:`🔗<class_DirAccess_property_include_hidden>`
  163. .. rst-class:: classref-property-setget
  164. - |void| **set_include_hidden**\ (\ value\: :ref:`bool<class_bool>`\ )
  165. - :ref:`bool<class_bool>` **get_include_hidden**\ (\ )
  166. If ``true``, hidden files are included when navigating the directory.
  167. 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>`.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_DirAccess_property_include_navigational:
  171. .. rst-class:: classref-property
  172. :ref:`bool<class_bool>` **include_navigational** :ref:`🔗<class_DirAccess_property_include_navigational>`
  173. .. rst-class:: classref-property-setget
  174. - |void| **set_include_navigational**\ (\ value\: :ref:`bool<class_bool>`\ )
  175. - :ref:`bool<class_bool>` **get_include_navigational**\ (\ )
  176. If ``true``, ``.`` and ``..`` are included when navigating the directory.
  177. Affects :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>` and :ref:`get_directories<class_DirAccess_method_get_directories>`.
  178. .. rst-class:: classref-section-separator
  179. ----
  180. .. rst-class:: classref-descriptions-group
  181. Method Descriptions
  182. -------------------
  183. .. _class_DirAccess_method_change_dir:
  184. .. rst-class:: classref-method
  185. :ref:`Error<enum_@GlobalScope_Error>` **change_dir**\ (\ to_dir\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_change_dir>`
  186. 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``).
  187. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  188. \ **Note:** The new directory must be within the same scope, e.g. when you had opened a directory inside ``res://``, you can't change it to ``user://`` directory. If you need to open a directory in another access scope, use :ref:`open<class_DirAccess_method_open>` to create a new instance instead.
  189. .. rst-class:: classref-item-separator
  190. ----
  191. .. _class_DirAccess_method_copy:
  192. .. rst-class:: classref-method
  193. :ref:`Error<enum_@GlobalScope_Error>` **copy**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`, chmod_flags\: :ref:`int<class_int>` = -1\ ) :ref:`🔗<class_DirAccess_method_copy>`
  194. 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.
  195. 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.
  196. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  197. .. rst-class:: classref-item-separator
  198. ----
  199. .. _class_DirAccess_method_copy_absolute:
  200. .. rst-class:: classref-method
  201. :ref:`Error<enum_@GlobalScope_Error>` **copy_absolute**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`, chmod_flags\: :ref:`int<class_int>` = -1\ ) |static| :ref:`🔗<class_DirAccess_method_copy_absolute>`
  202. Static version of :ref:`copy<class_DirAccess_method_copy>`. Supports only absolute paths.
  203. .. rst-class:: classref-item-separator
  204. ----
  205. .. _class_DirAccess_method_create_link:
  206. .. rst-class:: classref-method
  207. :ref:`Error<enum_@GlobalScope_Error>` **create_link**\ (\ source\: :ref:`String<class_String>`, target\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_create_link>`
  208. Creates symbolic link between files or folders.
  209. \ **Note:** On Windows, this method works only if the application is running with elevated privileges or Developer Mode is enabled.
  210. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  211. .. rst-class:: classref-item-separator
  212. ----
  213. .. _class_DirAccess_method_current_is_dir:
  214. .. rst-class:: classref-method
  215. :ref:`bool<class_bool>` **current_is_dir**\ (\ ) |const| :ref:`🔗<class_DirAccess_method_current_is_dir>`
  216. 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).
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_DirAccess_method_dir_exists:
  220. .. rst-class:: classref-method
  221. :ref:`bool<class_bool>` **dir_exists**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_dir_exists>`
  222. Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
  223. \ **Note:** The returned :ref:`bool<class_bool>` in the editor and after exporting when used on a path in the ``res://`` directory may be different. Some files are converted to engine-specific formats when exported, potentially changing the directory structure.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_DirAccess_method_dir_exists_absolute:
  227. .. rst-class:: classref-method
  228. :ref:`bool<class_bool>` **dir_exists_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_dir_exists_absolute>`
  229. Static version of :ref:`dir_exists<class_DirAccess_method_dir_exists>`. Supports only absolute paths.
  230. \ **Note:** The returned :ref:`bool<class_bool>` in the editor and after exporting when used on a path in the ``res://`` directory may be different. Some files are converted to engine-specific formats when exported, potentially changing the directory structure.
  231. .. rst-class:: classref-item-separator
  232. ----
  233. .. _class_DirAccess_method_file_exists:
  234. .. rst-class:: classref-method
  235. :ref:`bool<class_bool>` **file_exists**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_file_exists>`
  236. Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
  237. For a static equivalent, use :ref:`FileAccess.file_exists<class_FileAccess_method_file_exists>`.
  238. \ **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. See :ref:`ResourceLoader.exists<class_ResourceLoader_method_exists>` for an alternative approach that takes resource remapping into account.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_DirAccess_method_get_current_dir:
  242. .. rst-class:: classref-method
  243. :ref:`String<class_String>` **get_current_dir**\ (\ include_drive\: :ref:`bool<class_bool>` = true\ ) |const| :ref:`🔗<class_DirAccess_method_get_current_dir>`
  244. Returns the absolute path to the currently opened directory (e.g. ``res://folder`` or ``C:\tmp\folder``).
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_DirAccess_method_get_current_drive:
  248. .. rst-class:: classref-method
  249. :ref:`int<class_int>` **get_current_drive**\ (\ ) :ref:`🔗<class_DirAccess_method_get_current_drive>`
  250. 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.
  251. .. rst-class:: classref-item-separator
  252. ----
  253. .. _class_DirAccess_method_get_directories:
  254. .. rst-class:: classref-method
  255. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories**\ (\ ) :ref:`🔗<class_DirAccess_method_get_directories>`
  256. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files. The array is sorted alphabetically.
  257. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  258. \ **Note:** The returned directories in the editor and after exporting in the ``res://`` directory may differ as some files are converted to engine-specific formats when exported.
  259. .. rst-class:: classref-item-separator
  260. ----
  261. .. _class_DirAccess_method_get_directories_at:
  262. .. rst-class:: classref-method
  263. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories_at**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_directories_at>`
  264. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files, at the given ``path``. The array is sorted alphabetically.
  265. Use :ref:`get_directories<class_DirAccess_method_get_directories>` if you want more control of what gets included.
  266. \ **Note:** The returned directories in the editor and after exporting in the ``res://`` directory may differ as some files are converted to engine-specific formats when exported.
  267. .. rst-class:: classref-item-separator
  268. ----
  269. .. _class_DirAccess_method_get_drive_count:
  270. .. rst-class:: classref-method
  271. :ref:`int<class_int>` **get_drive_count**\ (\ ) |static| :ref:`🔗<class_DirAccess_method_get_drive_count>`
  272. On Windows, returns the number of drives (partitions) mounted on the current filesystem.
  273. On macOS, returns the number of mounted volumes.
  274. On Linux, returns the number of mounted volumes and GTK 3 bookmarks.
  275. On other platforms, the method returns 0.
  276. .. rst-class:: classref-item-separator
  277. ----
  278. .. _class_DirAccess_method_get_drive_name:
  279. .. rst-class:: classref-method
  280. :ref:`String<class_String>` **get_drive_name**\ (\ idx\: :ref:`int<class_int>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_drive_name>`
  281. On Windows, returns the name of the drive (partition) passed as an argument (e.g. ``C:``).
  282. On macOS, returns the path to the mounted volume passed as an argument.
  283. On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
  284. On other platforms, or if the requested drive does not exist, the method returns an empty String.
  285. .. rst-class:: classref-item-separator
  286. ----
  287. .. _class_DirAccess_method_get_files:
  288. .. rst-class:: classref-method
  289. :ref:`PackedStringArray<class_PackedStringArray>` **get_files**\ (\ ) :ref:`🔗<class_DirAccess_method_get_files>`
  290. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories. The array is sorted alphabetically.
  291. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>`.
  292. \ **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``.
  293. .. rst-class:: classref-item-separator
  294. ----
  295. .. _class_DirAccess_method_get_files_at:
  296. .. rst-class:: classref-method
  297. :ref:`PackedStringArray<class_PackedStringArray>` **get_files_at**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_files_at>`
  298. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories, at the given ``path``. The array is sorted alphabetically.
  299. Use :ref:`get_files<class_DirAccess_method_get_files>` if you want more control of what gets included.
  300. \ **Note:** When used on a ``res://`` path in an exported project, only the files 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 other 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 :ref:`ProjectSettings.editor/export/convert_text_resources_to_binary<class_ProjectSettings_property_editor/export/convert_text_resources_to_binary>`.
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_DirAccess_method_get_next:
  304. .. rst-class:: classref-method
  305. :ref:`String<class_String>` **get_next**\ (\ ) :ref:`🔗<class_DirAccess_method_get_next>`
  306. Returns the next element (file or directory) in the current directory.
  307. 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).
  308. .. rst-class:: classref-item-separator
  309. ----
  310. .. _class_DirAccess_method_get_open_error:
  311. .. rst-class:: classref-method
  312. :ref:`Error<enum_@GlobalScope_Error>` **get_open_error**\ (\ ) |static| :ref:`🔗<class_DirAccess_method_get_open_error>`
  313. Returns the result of the last :ref:`open<class_DirAccess_method_open>` call in the current thread.
  314. .. rst-class:: classref-item-separator
  315. ----
  316. .. _class_DirAccess_method_get_space_left:
  317. .. rst-class:: classref-method
  318. :ref:`int<class_int>` **get_space_left**\ (\ ) :ref:`🔗<class_DirAccess_method_get_space_left>`
  319. 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.
  320. .. rst-class:: classref-item-separator
  321. ----
  322. .. _class_DirAccess_method_is_case_sensitive:
  323. .. rst-class:: classref-method
  324. :ref:`bool<class_bool>` **is_case_sensitive**\ (\ path\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_DirAccess_method_is_case_sensitive>`
  325. Returns ``true`` if the file system or directory use case sensitive file names.
  326. \ **Note:** This method is implemented on macOS, Linux (for EXT4 and F2FS filesystems only) and Windows. On other platforms, it always returns ``true``.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_DirAccess_method_is_link:
  330. .. rst-class:: classref-method
  331. :ref:`bool<class_bool>` **is_link**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_is_link>`
  332. Returns ``true`` if the file or directory is a symbolic link, directory junction, or other reparse point.
  333. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  334. .. rst-class:: classref-item-separator
  335. ----
  336. .. _class_DirAccess_method_list_dir_begin:
  337. .. rst-class:: classref-method
  338. :ref:`Error<enum_@GlobalScope_Error>` **list_dir_begin**\ (\ ) :ref:`🔗<class_DirAccess_method_list_dir_begin>`
  339. 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>`.
  340. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  341. \ **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>`.
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_DirAccess_method_list_dir_end:
  345. .. rst-class:: classref-method
  346. |void| **list_dir_end**\ (\ ) :ref:`🔗<class_DirAccess_method_list_dir_end>`
  347. 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).
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_DirAccess_method_make_dir:
  351. .. rst-class:: classref-method
  352. :ref:`Error<enum_@GlobalScope_Error>` **make_dir**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_make_dir>`
  353. 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>`).
  354. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  355. .. rst-class:: classref-item-separator
  356. ----
  357. .. _class_DirAccess_method_make_dir_absolute:
  358. .. rst-class:: classref-method
  359. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_make_dir_absolute>`
  360. Static version of :ref:`make_dir<class_DirAccess_method_make_dir>`. Supports only absolute paths.
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_DirAccess_method_make_dir_recursive:
  364. .. rst-class:: classref-method
  365. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_make_dir_recursive>`
  366. 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.
  367. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  368. .. rst-class:: classref-item-separator
  369. ----
  370. .. _class_DirAccess_method_make_dir_recursive_absolute:
  371. .. rst-class:: classref-method
  372. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_make_dir_recursive_absolute>`
  373. Static version of :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`. Supports only absolute paths.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_DirAccess_method_open:
  377. .. rst-class:: classref-method
  378. :ref:`DirAccess<class_DirAccess>` **open**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_open>`
  379. 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``).
  380. 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.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_DirAccess_method_read_link:
  384. .. rst-class:: classref-method
  385. :ref:`String<class_String>` **read_link**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_read_link>`
  386. Returns target of the symbolic link.
  387. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  388. .. rst-class:: classref-item-separator
  389. ----
  390. .. _class_DirAccess_method_remove:
  391. .. rst-class:: classref-method
  392. :ref:`Error<enum_@GlobalScope_Error>` **remove**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_remove>`
  393. 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.
  394. If you don't want to delete the file/directory permanently, use :ref:`OS.move_to_trash<class_OS_method_move_to_trash>` instead.
  395. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  396. .. rst-class:: classref-item-separator
  397. ----
  398. .. _class_DirAccess_method_remove_absolute:
  399. .. rst-class:: classref-method
  400. :ref:`Error<enum_@GlobalScope_Error>` **remove_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_remove_absolute>`
  401. Static version of :ref:`remove<class_DirAccess_method_remove>`. Supports only absolute paths.
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_DirAccess_method_rename:
  405. .. rst-class:: classref-method
  406. :ref:`Error<enum_@GlobalScope_Error>` **rename**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_rename>`
  407. 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.
  408. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  409. .. rst-class:: classref-item-separator
  410. ----
  411. .. _class_DirAccess_method_rename_absolute:
  412. .. rst-class:: classref-method
  413. :ref:`Error<enum_@GlobalScope_Error>` **rename_absolute**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_rename_absolute>`
  414. Static version of :ref:`rename<class_DirAccess_method_rename>`. Supports only absolute paths.
  415. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  416. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  417. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  418. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  419. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  420. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  421. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  422. .. |void| replace:: :abbr:`void (No return value.)`