.. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead. .. _class_Directory: Directory ========= **Inherits:** :ref:`Reference` **<** :ref:`Object` **Category:** Core Brief Description ----------------- Type used to handle the filesystem. Member Functions ---------------- +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`open` **(** :ref:`String` path **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`list_dir_begin` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_next` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`current_is_dir` **(** **)** const | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | void | :ref:`list_dir_end` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_drive_count` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_drive` **(** :ref:`int` idx **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`change_dir` **(** :ref:`String` todir **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_current_dir` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`make_dir` **(** :ref:`String` name **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`make_dir_recursive` **(** :ref:`String` name **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`file_exists` **(** :ref:`String` name **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`dir_exists` **(** :ref:`String` name **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_space_left` **(** **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`copy` **(** :ref:`String` from, :ref:`String` to **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`rename` **(** :ref:`String` from, :ref:`String` to **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`remove` **(** :ref:`String` file **)** | +------------------------------+----------------------------------------------------------------------------------------------------------------------+ Description ----------- Directory type. Is used to manage directories and their content (not restricted to the project folder). Example for how to iterate through the files of a directory: :: func dir(path): var d = Directory.new() if d.open( path )==0: d.list_dir_begin() var file_name = d.get_next() while(file_name!=""): if d.current_is_dir(): print("Found directory: " + file_name) else: print("Found file:" + file_name) file_name = d.get_next() else: print("Some open Error, maybe directory not found?") Member Function Description --------------------------- .. _class_Directory_open: - Error **open** **(** :ref:`String` path **)** Opens a directory to work with. Needs a path, example "res://folder" .. _class_Directory_list_dir_begin: - :ref:`bool` **list_dir_begin** **(** **)** Loads all file names of the current directory (prepares the get_next() function). .. _class_Directory_get_next: - :ref:`String` **get_next** **(** **)** 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 ".." . Returns an empty String "" at the end of the list. .. _class_Directory_current_is_dir: - :ref:`bool` **current_is_dir** **(** **)** const Returns true if the current file you are looking at with get_next() is a directory or "." or ".." otherwise false. .. _class_Directory_list_dir_end: - void **list_dir_end** **(** **)** 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. .. _class_Directory_get_drive_count: - :ref:`int` **get_drive_count** **(** **)** .. _class_Directory_get_drive: - :ref:`String` **get_drive** **(** :ref:`int` idx **)** .. _class_Directory_change_dir: - Error **change_dir** **(** :ref:`String` todir **)** 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" .. _class_Directory_get_current_dir: - :ref:`String` **get_current_dir** **(** **)** Returns a path to the current directory, example: "res://folder" .. _class_Directory_make_dir: - Error **make_dir** **(** :ref:`String` name **)** .. _class_Directory_make_dir_recursive: - Error **make_dir_recursive** **(** :ref:`String` name **)** .. _class_Directory_file_exists: - :ref:`bool` **file_exists** **(** :ref:`String` name **)** .. _class_Directory_dir_exists: - :ref:`bool` **dir_exists** **(** :ref:`String` name **)** Returns true if directory exists otherwise false. Needs a path, example: "res://folder" .. _class_Directory_get_space_left: - :ref:`int` **get_space_left** **(** **)** .. _class_Directory_copy: - Error **copy** **(** :ref:`String` from, :ref:`String` to **)** .. _class_Directory_rename: - Error **rename** **(** :ref:`String` from, :ref:`String` to **)** .. _class_Directory_remove: - Error **remove** **(** :ref:`String` file **)**