Class GodotPath
- Namespace
- Cobilas.GodotEngine.Utility.IO
- Assembly
- com.cobilas.godot.utility.dll
The class allows manipulation of system paths in godot.
public static class GodotPath
- Inheritance
-
GodotPath
- Inherited Members
Fields
DirectorySeparatorChar
Contains the directory separator used in godot.
public const char DirectorySeparatorChar = '/'
Field Value
Properties
CurrentDirectory
Gets or sets the fully qualified path of the current working directory.
public static string CurrentDirectory { get; }
Property Value
- string
A string containing a directory path.
Exceptions
- ArgumentException
Attempted to set to an empty string ("").
- ArgumentNullException
Attempted to set to
null.
- IOException
An I/O error occurred.
- DirectoryNotFoundException
Attempted to set a local path that cannot be found.
- SecurityException
The caller does not have the appropriate permission.
PersistentFilePath
The path to the project's persistent files directory.
public static string PersistentFilePath { get; }
Property Value
- string
Returns a string containing the path to the project's persistent files directory.
ProjectPath
The path to the project's root folder.
public static string ProjectPath { get; }
Property Value
- string
Returns the root path of the project folder. When the project is compiled the property will use the CurrentDirectory property.
Methods
Combine(string, string)
Combines two strings into a path.
public static string Combine(string path1, string path2)
Parameters
Returns
- string
The combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If
path2
contains an absolute path, this method returnspath2
.
Exceptions
- ArgumentException
path1
orpath2
contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1
orpath2
is null.
Combine(string, string, string)
Combines three strings into a path.
public static string Combine(string path1, string path2, string path3)
Parameters
path1
stringThe first path to combine.
path2
stringThe second path to combine.
path3
stringThe third path to combine.
Returns
- string
The combined paths.
Exceptions
- ArgumentException
path1
,path2
, orpath3
contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1
,path2
, orpath3
is null.
Combine(string, string, string, string)
Combines four strings into a path.
public static string Combine(string path1, string path2, string path3, string path4)
Parameters
path1
stringThe first path to combine.
path2
stringThe second path to combine.
path3
stringThe third path to combine.
path4
stringThe fourth path to combine.
Returns
- string
The combined paths.
Exceptions
- ArgumentException
path1
,path2
,path3
, orpath4
contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1
,path2
,path3
, orpath4
is null.
Combine(params string[])
Combines an array of strings into a path.
public static string Combine(params string[] paths)
Parameters
paths
string[]An array of parts of the path.
Returns
- string
The combined paths.
Exceptions
- ArgumentException
One of the strings in the array contains one or more of the invalid characters defined in GetInvalidPathChars().
- ArgumentNullException
One of the strings in the array is null.
GetDirectoryName(string)
Returns the directory information for the specified path string.
public static string GetDirectoryName(string path)
Parameters
path
stringThe path of a file or directory.
Returns
- string
Directory information for
path
, or null ifpath
denotes a root directory or is null. Returns Empty ifpath
does not contain directory information.
Exceptions
- ArgumentException
The
path
parameter contains invalid characters, is empty, or contains only white spaces.- PathTooLongException
In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, IOException, instead.The
path
parameter is longer than the system-defined maximum length.
GetExtension(string)
Returns the extension of the specified path string.
public static string GetExtension(string path)
Parameters
path
stringThe path string from which to get the extension.
Returns
- string
The extension of the specified path (including the period "."), or null, or Empty. If
path
is null, GetExtension(string) returns null. Ifpath
does not have extension information, GetExtension(string) returns Empty.
Exceptions
- ArgumentException
path
contains one or more of the invalid characters defined in GetInvalidPathChars().
GetFileName(string)
Returns the file name and extension of the specified path string.
public static string GetFileName(string path)
Parameters
path
stringThe path string from which to obtain the file name and extension.
Returns
- string
The characters after the last directory character in
path
. If the last character ofpath
is a directory or volume separator character, this method returns Empty. Ifpath
is null, this method returns null.
Exceptions
- ArgumentException
path
contains one or more of the invalid characters defined in GetInvalidPathChars().
GetFileNameWithoutExtension(string)
Returns the file name of the specified path string without the extension.
public static string GetFileNameWithoutExtension(string path)
Parameters
path
stringThe path of the file.
Returns
- string
The string returned by GetFileName(string), minus the last period (.) and all characters following it.
Exceptions
- ArgumentException
path
contains one or more of the invalid characters defined in GetInvalidPathChars().
GetInvalidFileNameChars()
Gets an array containing the characters that are not allowed in file names.
public static char[] GetInvalidFileNameChars()
Returns
- char[]
An array containing the characters that are not allowed in file names.
GetInvalidPathChars()
Gets an array containing the characters that are not allowed in path names.
public static char[] GetInvalidPathChars()
Returns
- char[]
An array containing the characters that are not allowed in path names.
GetPathRoot(string)
Gets the root directory information of the specified path.
public static string GetPathRoot(string path)
Parameters
path
stringThe path from which to obtain root directory information.
Returns
- string
The root directory of
path
, such as "C:", or null ifpath
is null, or an empty string ifpath
does not contain root directory information.
Exceptions
- ArgumentException
path
contains one or more of the invalid characters defined in GetInvalidPathChars().-or- Empty was passed topath
.
GlobalizePath(string)
Returns the absolute, native OS path corresponding to the localized path
(starting with res://
or user://
). The returned path will vary depending on the operating system and user preferences. See File paths in Godot projects to see what those paths convert to. See also LocalizePath(string).
Note: GlobalizePath(string) with res://
will not work in an exported project. Instead, prepend the executable's base directory to the path when running from an exported project:
var path = ""
if OS.has_feature("editor"):
# Running from an editor binary.
# `path` will contain the absolute path to `hello.txt` located in the project root.
path = ProjectSettings.globalize_path("res://hello.txt")
else:
# Running from an exported project.
# `path` will contain the absolute path to `hello.txt` next to the executable.
# This is *not* identical to using `ProjectSettings.globalize_path()` with a `res://` path,
# but is close enough in spirit.
path = OS.get_executable_path().get_base_dir().plus_file("hello.txt")
public static string GlobalizePath(string path)
Parameters
path
string
Returns
HasExtension(string)
Determines whether a path includes a file name extension.
public static bool HasExtension(string path)
Parameters
path
stringThe path to search for an extension.
Returns
- bool
true if the characters that follow the last directory separator (\ or /) or volume separator (:) in the path include a period (.) followed by one or more characters; otherwise, false.
Exceptions
- ArgumentException
path
contains one or more of the invalid characters defined in GetInvalidPathChars().
IsInvalidFileName(string, out char)
Allows you to check if the system file name contains an invalid character.
public static bool IsInvalidFileName(string name, out char invalidChar)
Parameters
Returns
- bool
Returns
true
when an invalid character is encountered.