From cad1d27a6fc4399aac834781e5fdca65e6fce1ff Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 21 Apr 2022 13:10:36 +0200 Subject: Introduce more static methods to directory API --- doc/classes/DirAccess.xml | 93 ++++++++++++++++++++++++++++++++++++++++------ doc/classes/FileAccess.xml | 1 + 2 files changed, 82 insertions(+), 12 deletions(-) (limited to 'doc/classes') diff --git a/doc/classes/DirAccess.xml b/doc/classes/DirAccess.xml index de2e32b17b..cb7bf56f11 100644 --- a/doc/classes/DirAccess.xml +++ b/doc/classes/DirAccess.xml @@ -6,6 +6,15 @@ Directory type. It is used to manage directories and their content (not restricted to the project folder). [DirAccess] can't be instantiated directly. Instead it is created with a static method that takes a path for which it will be opened. + Most of the methods have a static alternative that can be used without creating a [DirAccess]. Static methods only support absolute paths (including [code]res://[/code] and [code]user://[/code]). + [codeblock] + # Standard + var dir = Directory.new() + dir.open("user://levels") + dir.make_dir("world1") + # Static + Directory.make_dir_absolute("user://levels/world1") + [/codeblock] [b]Note:[/b] 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 [ResourceLoader] to access imported resources. Here is an example on how to iterate through the files of a directory: [codeblocks] @@ -59,7 +68,7 @@ - + Changes the currently opened directory to the one passed as an argument. The argument can be relative to the current directory (e.g. [code]newdir[/code] or [code]../newdir[/code]), or an absolute path (e.g. [code]/tmp/newdir[/code] or [code]res://somedir/newdir[/code]). Returns one of the [enum Error] code constants ([code]OK[/code] on success). @@ -76,6 +85,15 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). + + + + + + + Static version of [method copy]. Supports only absolute paths. + + @@ -87,7 +105,13 @@ Returns whether the target directory exists. The argument can be relative to the current directory, or an absolute path. - If the [DirAccess] is not open, the path is relative to [code]res://[/code]. + + + + + + + Static version of [method dir_exists]. Supports only absolute paths. @@ -95,7 +119,7 @@ Returns whether the target file exists. The argument can be relative to the current directory, or an absolute path. - If the [DirAccess] is not open, the path is relative to [code]res://[/code]. + For a static equivalent, use [method FileAccess.file_exists]. @@ -108,7 +132,7 @@ - Returns the currently opened directory's drive index. See [method get_drive] to convert returned index to the name of the drive. + Returns the currently opened directory's drive index. See [method get_drive_name] to convert returned index to the name of the drive. @@ -118,17 +142,15 @@ Affected by [member include_hidden] and [member include_navigational]. - - - + + + - On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]). - On macOS, returns the path to the mounted volume passed as an argument. - On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument. - On other platforms, or if the requested drive does not exist, the method returns an empty String. + Returns a [PackedStringArray] containing filenames of the directory contents, excluding files, at the given [param path]. The array is sorted alphabetically. + Use [method get_directories] if you want more control of what gets included. - + On Windows, returns the number of drives (partitions) mounted on the current filesystem. @@ -137,6 +159,16 @@ On other platforms, the method returns 0. + + + + + On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]). + On macOS, returns the path to the mounted volume passed as an argument. + On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument. + On other platforms, or if the requested drive does not exist, the method returns an empty String. + + @@ -144,6 +176,14 @@ Affected by [member include_hidden]. + + + + + Returns a [PackedStringArray] containing filenames of the directory contents, excluding directories, at the given [param path]. The array is sorted alphabetically. + Use [method get_files] if you want more control of what gets included. + + @@ -185,6 +225,13 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). + + + + + Static version of [method make_dir]. Supports only absolute paths. + + @@ -193,6 +240,13 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). + + + + + Static version of [method make_dir_recursive]. Supports only absolute paths. + + @@ -210,6 +264,13 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). + + + + + Static version of [method remove]. Supports only absolute paths. + + @@ -219,6 +280,14 @@ Returns one of the [enum Error] code constants ([code]OK[/code] on success). + + + + + + Static version of [method rename]. Supports only absolute paths. + + diff --git a/doc/classes/FileAccess.xml b/doc/classes/FileAccess.xml index 32f6a1dd3e..adc0f4c3dd 100644 --- a/doc/classes/FileAccess.xml +++ b/doc/classes/FileAccess.xml @@ -77,6 +77,7 @@ Returns [code]true[/code] if the file exists in the given path. [b]Note:[/b] Many resources types are imported (e.g. textures or sound files), and their source asset will not be included in the exported game, as only the imported version is used. See [method ResourceLoader.exists] for an alternative approach that takes resource remapping into account. + For a non-static, relative equivalent, use [method DirAccess.file_exists]. -- cgit v1.2.3