Class GodotPath
- Namespace
- Cobilas.GodotEngine.Utility.IO
- Assembly
- com.cobilas.godot.utility.dll
Provides utilities for manipulating file system paths in Godot.
public static class GodotPath
- Inheritance
-
GodotPath
- Inherited Members
Remarks
This class handles both regular file system paths and Godot-specific paths (res:// and user://). It provides methods for path manipulation while maintaining Godot's path conventions.
Fields
DirectorySeparatorChar
Contains the directory separator used in godot.
public const char DirectorySeparatorChar = '/'
Field Value
ResPath
The prefix for resource paths in Godot.
public const string ResPath = "res://"
Field Value
Remarks
Resources with this prefix are loaded from the project's resource directory.
UserPath
The prefix for user data paths in Godot.
public const string UserPath = "user://"
Field Value
Remarks
Files with this prefix are stored in the user's persistent data directory.
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
path2contains an absolute path, this method returnspath2.
Exceptions
- ArgumentException
path1orpath2contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1orpath2is null.
Combine(string, string, string)
Combines three strings into a path.
public static string Combine(string path1, string path2, string path3)
Parameters
path1stringThe first path to combine.
path2stringThe second path to combine.
path3stringThe third path to combine.
Returns
- string
The combined paths.
Exceptions
- ArgumentException
path1,path2, orpath3contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1,path2, orpath3is 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
path1stringThe first path to combine.
path2stringThe second path to combine.
path3stringThe third path to combine.
path4stringThe fourth path to combine.
Returns
- string
The combined paths.
Exceptions
- ArgumentException
path1,path2,path3, orpath4contains one or more of the invalid characters defined in GetInvalidPathChars().- ArgumentNullException
path1,path2,path3, orpath4is null.
Combine(params string[])
Combines an array of strings into a path.
public static string Combine(params string[] paths)
Parameters
pathsstring[]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
pathstringThe path of a file or directory.
Returns
- string
Directory information for
path, or null ifpathdenotes a root directory or is null. Returns Empty ifpathdoes not contain directory information.
Exceptions
- ArgumentException
The
pathparameter 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
pathparameter 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
pathstringThe path string from which to get the extension.
Returns
- string
The extension of the specified path (including the period "."), or null, or Empty. If
pathis null, GetExtension(string) returns null. Ifpathdoes not have extension information, GetExtension(string) returns Empty.
Exceptions
- ArgumentException
pathcontains 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
pathstringThe 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 ofpathis a directory or volume separator character, this method returns Empty. Ifpathis null, this method returns null.
Exceptions
- ArgumentException
pathcontains 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
pathstringThe path of the file.
Returns
- string
The string returned by GetFileName(string), minus the last period (.) and all characters following it.
Exceptions
- ArgumentException
pathcontains 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
pathstringThe path from which to obtain root directory information.
Returns
- string
The root directory of
path, such as "C:", or null ifpathis null, or an empty string ifpathdoes not contain root directory information.
Exceptions
- ArgumentException
pathcontains 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
pathstring
Returns
HasExtension(string)
Determines whether a path includes a file name extension.
public static bool HasExtension(string path)
Parameters
pathstringThe 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
pathcontains one or more of the invalid characters defined in GetInvalidPathChars().
IsGodotRoot(string)
Determines whether the specified path is a Godot root path.
public static bool IsGodotRoot(string path)
Parameters
pathstringThe path to check.
Returns
Remarks
This method checks if a path is one of Godot's special root paths (res:// or user://). It is useful for determining if a path refers to a Godot resource or user data.
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
truewhen an invalid character is encountered.