class_directory.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Directory:
  4. Directory
  5. =========
  6. **Inherits:** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  7. **Category:** Core
  8. Brief Description
  9. -----------------
  10. Type used to handle the filesystem.
  11. Member Functions
  12. ----------------
  13. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  14. | Error | :ref:`open<class_Directory_open>` **(** :ref:`String<class_string>` path **)** |
  15. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`bool<class_bool>` | :ref:`list_dir_begin<class_Directory_list_dir_begin>` **(** **)** |
  17. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`String<class_string>` | :ref:`get_next<class_Directory_get_next>` **(** **)** |
  19. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`bool<class_bool>` | :ref:`current_is_dir<class_Directory_current_is_dir>` **(** **)** const |
  21. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  22. | void | :ref:`list_dir_end<class_Directory_list_dir_end>` **(** **)** |
  23. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`int<class_int>` | :ref:`get_drive_count<class_Directory_get_drive_count>` **(** **)** |
  25. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_string>` | :ref:`get_drive<class_Directory_get_drive>` **(** :ref:`int<class_int>` idx **)** |
  27. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  28. | Error | :ref:`change_dir<class_Directory_change_dir>` **(** :ref:`String<class_string>` todir **)** |
  29. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_string>` | :ref:`get_current_dir<class_Directory_get_current_dir>` **(** **)** |
  31. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  32. | Error | :ref:`make_dir<class_Directory_make_dir>` **(** :ref:`String<class_string>` name **)** |
  33. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  34. | Error | :ref:`make_dir_recursive<class_Directory_make_dir_recursive>` **(** :ref:`String<class_string>` name **)** |
  35. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`bool<class_bool>` | :ref:`file_exists<class_Directory_file_exists>` **(** :ref:`String<class_string>` name **)** |
  37. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`bool<class_bool>` | :ref:`dir_exists<class_Directory_dir_exists>` **(** :ref:`String<class_string>` name **)** |
  39. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`get_space_left<class_Directory_get_space_left>` **(** **)** |
  41. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  42. | Error | :ref:`copy<class_Directory_copy>` **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)** |
  43. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  44. | Error | :ref:`rename<class_Directory_rename>` **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)** |
  45. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  46. | Error | :ref:`remove<class_Directory_remove>` **(** :ref:`String<class_string>` file **)** |
  47. +------------------------------+----------------------------------------------------------------------------------------------------------------------+
  48. Description
  49. -----------
  50. Directory type. Is used to manage directories and their content (not restricted to the project folder).
  51. Example for how to iterate through the files of a directory:
  52. ::
  53. func dir(path):
  54. var d = Directory.new()
  55. if d.open( path )==0:
  56. d.list_dir_begin()
  57. var file_name = d.get_next()
  58. while(file_name!=""):
  59. if d.current_is_dir():
  60. print("Found directory: " + file_name)
  61. else:
  62. print("Found file:" + file_name)
  63. file_name = d.get_next()
  64. else:
  65. print("Some open Error, maybe directory not found?")
  66. Member Function Description
  67. ---------------------------
  68. .. _class_Directory_open:
  69. - Error **open** **(** :ref:`String<class_string>` path **)**
  70. Opens a directory to work with. Needs a path, example "res://folder"
  71. .. _class_Directory_list_dir_begin:
  72. - :ref:`bool<class_bool>` **list_dir_begin** **(** **)**
  73. Loads all file names of the current directory (prepares the get_next() function).
  74. .. _class_Directory_get_next:
  75. - :ref:`String<class_string>` **get_next** **(** **)**
  76. Is used to iterate through the files of the current directory. Returns the name(no path) of the current file/directory, it also contains "." and ".." .
  77. Returns an empty String "" at the end of the list.
  78. .. _class_Directory_current_is_dir:
  79. - :ref:`bool<class_bool>` **current_is_dir** **(** **)** const
  80. Returns true if the current file you are looking at with get_next() is a directory or "." or ".." otherwise false.
  81. .. _class_Directory_list_dir_end:
  82. - void **list_dir_end** **(** **)**
  83. Run this to empty the list of remaining files in get_next(). You can use it to end the iteration, as soon as your goal is reached.
  84. .. _class_Directory_get_drive_count:
  85. - :ref:`int<class_int>` **get_drive_count** **(** **)**
  86. .. _class_Directory_get_drive:
  87. - :ref:`String<class_string>` **get_drive** **(** :ref:`int<class_int>` idx **)**
  88. .. _class_Directory_change_dir:
  89. - Error **change_dir** **(** :ref:`String<class_string>` todir **)**
  90. Needs a path or name to the next directory. When the target directory is in the current directory you can use "newfolder" otherwise you need the full path "res://currentfolder/newfolder"
  91. .. _class_Directory_get_current_dir:
  92. - :ref:`String<class_string>` **get_current_dir** **(** **)**
  93. Returns a path to the current directory, example: "res://folder"
  94. .. _class_Directory_make_dir:
  95. - Error **make_dir** **(** :ref:`String<class_string>` name **)**
  96. .. _class_Directory_make_dir_recursive:
  97. - Error **make_dir_recursive** **(** :ref:`String<class_string>` name **)**
  98. .. _class_Directory_file_exists:
  99. - :ref:`bool<class_bool>` **file_exists** **(** :ref:`String<class_string>` name **)**
  100. .. _class_Directory_dir_exists:
  101. - :ref:`bool<class_bool>` **dir_exists** **(** :ref:`String<class_string>` name **)**
  102. Returns true if directory exists otherwise false. Needs a path, example: "res://folder"
  103. .. _class_Directory_get_space_left:
  104. - :ref:`int<class_int>` **get_space_left** **(** **)**
  105. .. _class_Directory_copy:
  106. - Error **copy** **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)**
  107. .. _class_Directory_rename:
  108. - Error **rename** **(** :ref:`String<class_string>` from, :ref:`String<class_string>` to **)**
  109. .. _class_Directory_remove:
  110. - Error **remove** **(** :ref:`String<class_string>` file **)**