class_diraccess.rst 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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/4.3/doc/tools/make_rst.py.
  7. .. XML source: https://github.com/godotengine/godot/tree/4.3/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:** 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.
  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. .. rst-class:: classref-introduction-group
  69. Tutorials
  70. ---------
  71. - :doc:`File system <../tutorials/scripting/filesystem>`
  72. .. rst-class:: classref-reftable-group
  73. Properties
  74. ----------
  75. .. table::
  76. :widths: auto
  77. +-------------------------+----------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`include_hidden<class_DirAccess_property_include_hidden>` |
  79. +-------------------------+----------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`include_navigational<class_DirAccess_property_include_navigational>` |
  81. +-------------------------+----------------------------------------------------------------------------+
  82. .. rst-class:: classref-reftable-group
  83. Methods
  84. -------
  85. .. table::
  86. :widths: auto
  87. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`change_dir<class_DirAccess_method_change_dir>`\ (\ to_dir\: :ref:`String<class_String>`\ ) |
  89. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :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\ ) |
  91. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :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| |
  93. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`create_link<class_DirAccess_method_create_link>`\ (\ source\: :ref:`String<class_String>`, target\: :ref:`String<class_String>`\ ) |
  95. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`bool<class_bool>` | :ref:`current_is_dir<class_DirAccess_method_current_is_dir>`\ (\ ) |const| |
  97. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`bool<class_bool>` | :ref:`dir_exists<class_DirAccess_method_dir_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |
  99. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`bool<class_bool>` | :ref:`dir_exists_absolute<class_DirAccess_method_dir_exists_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  101. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`bool<class_bool>` | :ref:`file_exists<class_DirAccess_method_file_exists>`\ (\ path\: :ref:`String<class_String>`\ ) |
  103. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`String<class_String>` | :ref:`get_current_dir<class_DirAccess_method_get_current_dir>`\ (\ include_drive\: :ref:`bool<class_bool>` = true\ ) |const| |
  105. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`int<class_int>` | :ref:`get_current_drive<class_DirAccess_method_get_current_drive>`\ (\ ) |
  107. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories<class_DirAccess_method_get_directories>`\ (\ ) |
  109. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_directories_at<class_DirAccess_method_get_directories_at>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  111. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`int<class_int>` | :ref:`get_drive_count<class_DirAccess_method_get_drive_count>`\ (\ ) |static| |
  113. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`String<class_String>` | :ref:`get_drive_name<class_DirAccess_method_get_drive_name>`\ (\ idx\: :ref:`int<class_int>`\ ) |static| |
  115. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files<class_DirAccess_method_get_files>`\ (\ ) |
  117. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_files_at<class_DirAccess_method_get_files_at>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  119. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`String<class_String>` | :ref:`get_next<class_DirAccess_method_get_next>`\ (\ ) |
  121. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`get_open_error<class_DirAccess_method_get_open_error>`\ (\ ) |static| |
  123. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`int<class_int>` | :ref:`get_space_left<class_DirAccess_method_get_space_left>`\ (\ ) |
  125. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`is_case_sensitive<class_DirAccess_method_is_case_sensitive>`\ (\ path\: :ref:`String<class_String>`\ ) |const| |
  127. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`bool<class_bool>` | :ref:`is_link<class_DirAccess_method_is_link>`\ (\ path\: :ref:`String<class_String>`\ ) |
  129. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>`\ (\ ) |
  131. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | |void| | :ref:`list_dir_end<class_DirAccess_method_list_dir_end>`\ (\ ) |
  133. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir<class_DirAccess_method_make_dir>`\ (\ path\: :ref:`String<class_String>`\ ) |
  135. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_absolute<class_DirAccess_method_make_dir_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  137. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`\ (\ path\: :ref:`String<class_String>`\ ) |
  139. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`make_dir_recursive_absolute<class_DirAccess_method_make_dir_recursive_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  141. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`DirAccess<class_DirAccess>` | :ref:`open<class_DirAccess_method_open>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  143. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | :ref:`String<class_String>` | :ref:`read_link<class_DirAccess_method_read_link>`\ (\ path\: :ref:`String<class_String>`\ ) |
  145. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove<class_DirAccess_method_remove>`\ (\ path\: :ref:`String<class_String>`\ ) |
  147. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`remove_absolute<class_DirAccess_method_remove_absolute>`\ (\ path\: :ref:`String<class_String>`\ ) |static| |
  149. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename<class_DirAccess_method_rename>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |
  151. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`rename_absolute<class_DirAccess_method_rename_absolute>`\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |static| |
  153. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. .. rst-class:: classref-section-separator
  155. ----
  156. .. rst-class:: classref-descriptions-group
  157. Property Descriptions
  158. ---------------------
  159. .. _class_DirAccess_property_include_hidden:
  160. .. rst-class:: classref-property
  161. :ref:`bool<class_bool>` **include_hidden** :ref:`🔗<class_DirAccess_property_include_hidden>`
  162. .. rst-class:: classref-property-setget
  163. - |void| **set_include_hidden**\ (\ value\: :ref:`bool<class_bool>`\ )
  164. - :ref:`bool<class_bool>` **get_include_hidden**\ (\ )
  165. If ``true``, hidden files are included when navigating the directory.
  166. 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>`.
  167. .. rst-class:: classref-item-separator
  168. ----
  169. .. _class_DirAccess_property_include_navigational:
  170. .. rst-class:: classref-property
  171. :ref:`bool<class_bool>` **include_navigational** :ref:`🔗<class_DirAccess_property_include_navigational>`
  172. .. rst-class:: classref-property-setget
  173. - |void| **set_include_navigational**\ (\ value\: :ref:`bool<class_bool>`\ )
  174. - :ref:`bool<class_bool>` **get_include_navigational**\ (\ )
  175. If ``true``, ``.`` and ``..`` are included when navigating the directory.
  176. Affects :ref:`list_dir_begin<class_DirAccess_method_list_dir_begin>` and :ref:`get_directories<class_DirAccess_method_get_directories>`.
  177. .. rst-class:: classref-section-separator
  178. ----
  179. .. rst-class:: classref-descriptions-group
  180. Method Descriptions
  181. -------------------
  182. .. _class_DirAccess_method_change_dir:
  183. .. rst-class:: classref-method
  184. :ref:`Error<enum_@GlobalScope_Error>` **change_dir**\ (\ to_dir\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_change_dir>`
  185. 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``).
  186. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  187. \ **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.
  188. .. rst-class:: classref-item-separator
  189. ----
  190. .. _class_DirAccess_method_copy:
  191. .. rst-class:: classref-method
  192. :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>`
  193. 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.
  194. 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.
  195. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  196. .. rst-class:: classref-item-separator
  197. ----
  198. .. _class_DirAccess_method_copy_absolute:
  199. .. rst-class:: classref-method
  200. :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>`
  201. Static version of :ref:`copy<class_DirAccess_method_copy>`. Supports only absolute paths.
  202. .. rst-class:: classref-item-separator
  203. ----
  204. .. _class_DirAccess_method_create_link:
  205. .. rst-class:: classref-method
  206. :ref:`Error<enum_@GlobalScope_Error>` **create_link**\ (\ source\: :ref:`String<class_String>`, target\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_create_link>`
  207. Creates symbolic link between files or folders.
  208. \ **Note:** On Windows, this method works only if the application is running with elevated privileges or Developer Mode is enabled.
  209. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  210. .. rst-class:: classref-item-separator
  211. ----
  212. .. _class_DirAccess_method_current_is_dir:
  213. .. rst-class:: classref-method
  214. :ref:`bool<class_bool>` **current_is_dir**\ (\ ) |const| :ref:`🔗<class_DirAccess_method_current_is_dir>`
  215. 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).
  216. .. rst-class:: classref-item-separator
  217. ----
  218. .. _class_DirAccess_method_dir_exists:
  219. .. rst-class:: classref-method
  220. :ref:`bool<class_bool>` **dir_exists**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_dir_exists>`
  221. Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path.
  222. .. rst-class:: classref-item-separator
  223. ----
  224. .. _class_DirAccess_method_dir_exists_absolute:
  225. .. rst-class:: classref-method
  226. :ref:`bool<class_bool>` **dir_exists_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_dir_exists_absolute>`
  227. Static version of :ref:`dir_exists<class_DirAccess_method_dir_exists>`. Supports only absolute paths.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_DirAccess_method_file_exists:
  231. .. rst-class:: classref-method
  232. :ref:`bool<class_bool>` **file_exists**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_file_exists>`
  233. Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path.
  234. For a static equivalent, use :ref:`FileAccess.file_exists<class_FileAccess_method_file_exists>`.
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_DirAccess_method_get_current_dir:
  238. .. rst-class:: classref-method
  239. :ref:`String<class_String>` **get_current_dir**\ (\ include_drive\: :ref:`bool<class_bool>` = true\ ) |const| :ref:`🔗<class_DirAccess_method_get_current_dir>`
  240. Returns the absolute path to the currently opened directory (e.g. ``res://folder`` or ``C:\tmp\folder``).
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_DirAccess_method_get_current_drive:
  244. .. rst-class:: classref-method
  245. :ref:`int<class_int>` **get_current_drive**\ (\ ) :ref:`🔗<class_DirAccess_method_get_current_drive>`
  246. 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.
  247. .. rst-class:: classref-item-separator
  248. ----
  249. .. _class_DirAccess_method_get_directories:
  250. .. rst-class:: classref-method
  251. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories**\ (\ ) :ref:`🔗<class_DirAccess_method_get_directories>`
  252. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files. The array is sorted alphabetically.
  253. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_DirAccess_method_get_directories_at:
  257. .. rst-class:: classref-method
  258. :ref:`PackedStringArray<class_PackedStringArray>` **get_directories_at**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_directories_at>`
  259. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding files, at the given ``path``. The array is sorted alphabetically.
  260. Use :ref:`get_directories<class_DirAccess_method_get_directories>` if you want more control of what gets included.
  261. .. rst-class:: classref-item-separator
  262. ----
  263. .. _class_DirAccess_method_get_drive_count:
  264. .. rst-class:: classref-method
  265. :ref:`int<class_int>` **get_drive_count**\ (\ ) |static| :ref:`🔗<class_DirAccess_method_get_drive_count>`
  266. On Windows, returns the number of drives (partitions) mounted on the current filesystem.
  267. On macOS, returns the number of mounted volumes.
  268. On Linux, returns the number of mounted volumes and GTK 3 bookmarks.
  269. On other platforms, the method returns 0.
  270. .. rst-class:: classref-item-separator
  271. ----
  272. .. _class_DirAccess_method_get_drive_name:
  273. .. rst-class:: classref-method
  274. :ref:`String<class_String>` **get_drive_name**\ (\ idx\: :ref:`int<class_int>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_drive_name>`
  275. On Windows, returns the name of the drive (partition) passed as an argument (e.g. ``C:``).
  276. On macOS, returns the path to the mounted volume passed as an argument.
  277. On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
  278. On other platforms, or if the requested drive does not exist, the method returns an empty String.
  279. .. rst-class:: classref-item-separator
  280. ----
  281. .. _class_DirAccess_method_get_files:
  282. .. rst-class:: classref-method
  283. :ref:`PackedStringArray<class_PackedStringArray>` **get_files**\ (\ ) :ref:`🔗<class_DirAccess_method_get_files>`
  284. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories. The array is sorted alphabetically.
  285. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>`.
  286. \ **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``.
  287. .. rst-class:: classref-item-separator
  288. ----
  289. .. _class_DirAccess_method_get_files_at:
  290. .. rst-class:: classref-method
  291. :ref:`PackedStringArray<class_PackedStringArray>` **get_files_at**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_get_files_at>`
  292. Returns a :ref:`PackedStringArray<class_PackedStringArray>` containing filenames of the directory contents, excluding directories, at the given ``path``. The array is sorted alphabetically.
  293. Use :ref:`get_files<class_DirAccess_method_get_files>` if you want more control of what gets included.
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_DirAccess_method_get_next:
  297. .. rst-class:: classref-method
  298. :ref:`String<class_String>` **get_next**\ (\ ) :ref:`🔗<class_DirAccess_method_get_next>`
  299. Returns the next element (file or directory) in the current directory.
  300. 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).
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_DirAccess_method_get_open_error:
  304. .. rst-class:: classref-method
  305. :ref:`Error<enum_@GlobalScope_Error>` **get_open_error**\ (\ ) |static| :ref:`🔗<class_DirAccess_method_get_open_error>`
  306. Returns the result of the last :ref:`open<class_DirAccess_method_open>` call in the current thread.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_DirAccess_method_get_space_left:
  310. .. rst-class:: classref-method
  311. :ref:`int<class_int>` **get_space_left**\ (\ ) :ref:`🔗<class_DirAccess_method_get_space_left>`
  312. 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.
  313. .. rst-class:: classref-item-separator
  314. ----
  315. .. _class_DirAccess_method_is_case_sensitive:
  316. .. rst-class:: classref-method
  317. :ref:`bool<class_bool>` **is_case_sensitive**\ (\ path\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_DirAccess_method_is_case_sensitive>`
  318. Returns ``true`` if the file system or directory use case sensitive file names.
  319. \ **Note:** This method is implemented on macOS, Linux (for EXT4 and F2FS filesystems only) and Windows. On other platforms, it always returns ``true``.
  320. .. rst-class:: classref-item-separator
  321. ----
  322. .. _class_DirAccess_method_is_link:
  323. .. rst-class:: classref-method
  324. :ref:`bool<class_bool>` **is_link**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_is_link>`
  325. Returns ``true`` if the file or directory is a symbolic link, directory junction, or other reparse point.
  326. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  327. .. rst-class:: classref-item-separator
  328. ----
  329. .. _class_DirAccess_method_list_dir_begin:
  330. .. rst-class:: classref-method
  331. :ref:`Error<enum_@GlobalScope_Error>` **list_dir_begin**\ (\ ) :ref:`🔗<class_DirAccess_method_list_dir_begin>`
  332. 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>`.
  333. Affected by :ref:`include_hidden<class_DirAccess_property_include_hidden>` and :ref:`include_navigational<class_DirAccess_property_include_navigational>`.
  334. \ **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>`.
  335. .. rst-class:: classref-item-separator
  336. ----
  337. .. _class_DirAccess_method_list_dir_end:
  338. .. rst-class:: classref-method
  339. |void| **list_dir_end**\ (\ ) :ref:`🔗<class_DirAccess_method_list_dir_end>`
  340. 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).
  341. .. rst-class:: classref-item-separator
  342. ----
  343. .. _class_DirAccess_method_make_dir:
  344. .. rst-class:: classref-method
  345. :ref:`Error<enum_@GlobalScope_Error>` **make_dir**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_make_dir>`
  346. 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>`).
  347. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_DirAccess_method_make_dir_absolute:
  351. .. rst-class:: classref-method
  352. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_make_dir_absolute>`
  353. Static version of :ref:`make_dir<class_DirAccess_method_make_dir>`. Supports only absolute paths.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_DirAccess_method_make_dir_recursive:
  357. .. rst-class:: classref-method
  358. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_make_dir_recursive>`
  359. 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.
  360. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  361. .. rst-class:: classref-item-separator
  362. ----
  363. .. _class_DirAccess_method_make_dir_recursive_absolute:
  364. .. rst-class:: classref-method
  365. :ref:`Error<enum_@GlobalScope_Error>` **make_dir_recursive_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_make_dir_recursive_absolute>`
  366. Static version of :ref:`make_dir_recursive<class_DirAccess_method_make_dir_recursive>`. Supports only absolute paths.
  367. .. rst-class:: classref-item-separator
  368. ----
  369. .. _class_DirAccess_method_open:
  370. .. rst-class:: classref-method
  371. :ref:`DirAccess<class_DirAccess>` **open**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_open>`
  372. 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``).
  373. 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.
  374. .. rst-class:: classref-item-separator
  375. ----
  376. .. _class_DirAccess_method_read_link:
  377. .. rst-class:: classref-method
  378. :ref:`String<class_String>` **read_link**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_read_link>`
  379. Returns target of the symbolic link.
  380. \ **Note:** This method is implemented on macOS, Linux, and Windows.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_DirAccess_method_remove:
  384. .. rst-class:: classref-method
  385. :ref:`Error<enum_@GlobalScope_Error>` **remove**\ (\ path\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_remove>`
  386. 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.
  387. If you don't want to delete the file/directory permanently, use :ref:`OS.move_to_trash<class_OS_method_move_to_trash>` instead.
  388. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  389. .. rst-class:: classref-item-separator
  390. ----
  391. .. _class_DirAccess_method_remove_absolute:
  392. .. rst-class:: classref-method
  393. :ref:`Error<enum_@GlobalScope_Error>` **remove_absolute**\ (\ path\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_remove_absolute>`
  394. Static version of :ref:`remove<class_DirAccess_method_remove>`. Supports only absolute paths.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _class_DirAccess_method_rename:
  398. .. rst-class:: classref-method
  399. :ref:`Error<enum_@GlobalScope_Error>` **rename**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) :ref:`🔗<class_DirAccess_method_rename>`
  400. 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.
  401. Returns one of the :ref:`Error<enum_@GlobalScope_Error>` code constants (:ref:`@GlobalScope.OK<class_@GlobalScope_constant_OK>` on success).
  402. .. rst-class:: classref-item-separator
  403. ----
  404. .. _class_DirAccess_method_rename_absolute:
  405. .. rst-class:: classref-method
  406. :ref:`Error<enum_@GlobalScope_Error>` **rename_absolute**\ (\ from\: :ref:`String<class_String>`, to\: :ref:`String<class_String>`\ ) |static| :ref:`🔗<class_DirAccess_method_rename_absolute>`
  407. Static version of :ref:`rename<class_DirAccess_method_rename>`. Supports only absolute paths.
  408. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  409. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  410. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  411. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  412. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  413. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  414. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  415. .. |void| replace:: :abbr:`void (No return value.)`