class_diraccess.rst 35 KB

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