Class FilePathExtensions
Extension methods that expose FilePathUtil path operations directly on string instances, enabling a fluent style for common path manipulation tasks. Every method in this class delegates to its corresponding static method in FilePathUtil and inherits that method's documented behavior, null handling, and return-value contracts.
The extensions are organized into four groups:
- Path Operations - normalize separators, convert to forward or back slashes.
- Path Component Extraction - retrieve the parent directory, file name, file name without extension, extension, or drive/UNC root.
- Path Validation - check whether a string is a valid path, an absolute path, a root path, or contains invalid path or file name characters.
- Path Transformation - sanitize a file name by replacing invalid characters, or swap the file extension.
Inherited Members
Namespace: Scylla.Core.Util.File
Assembly: ScyllaCore.dll
Syntax
public static class FilePathExtensions
Methods
ChangePathExtension(string, string)
Replaces the extension of path with
newExtension, delegating to
ChangeExtension(string, string).
Declaration
public static string ChangePathExtension(this string path, string newExtension)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path whose extension should be replaced. |
| string | newExtension | The replacement extension. May include or omit the leading dot; ChangeExtension(string, string) normalizes this automatically. Pass null or an empty string to remove the extension entirely. |
Returns
| Type | Description |
|---|---|
| string | The modified path with the new extension, or the original |
See Also
ContainsInvalidFileNameChars(string)
Determines whether a file name string (not a full path) contains any character that is illegal in file names on the current platform.
Declaration
public static bool ContainsInvalidFileNameChars(this string fileName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileName | The file name component to inspect (must not include directory separators). |
Returns
| Type | Description |
|---|---|
| bool | true if |
See Also
ContainsInvalidPathChars(string)
Determines whether a path string contains any character that is illegal in file system paths on the current platform.
Declaration
public static bool ContainsInvalidPathChars(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path string to inspect. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Remarks
Uses a simple nested loop against InvalidPathChars for allocation-free checking. Call IsValidPath(string) for a combined null/empty/invalid-chars check.
GetPathExtension(string)
Returns the extension of the specified path string, always including the leading dot character, equivalent to GetExtension(ReadOnlySpan<char>).
Declaration
public static string GetPathExtension(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to examine. Only the last path component is considered. |
Returns
| Type | Description |
|---|---|
| string | The extension including the leading dot (e.g., |
See Also
GetPathFileName(string)
Extracts the file name and extension from the last component of the specified path, equivalent to GetFileName(ReadOnlySpan<char>).
Declaration
public static string GetPathFileName(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The full or partial file path to examine. May be a relative or absolute path. |
Returns
| Type | Description |
|---|---|
| string | The file name with extension (e.g., |
See Also
GetPathFileNameWithoutExtension(string)
Extracts the file name without its extension from the last component of the specified path, equivalent to GetFileNameWithoutExtension(ReadOnlySpan<char>).
Declaration
public static string GetPathFileNameWithoutExtension(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The full or partial file path to examine. |
Returns
| Type | Description |
|---|---|
| string | The file name without the extension (e.g., |
See Also
GetPathParent(string)
Returns the directory component of the specified path, equivalent to GetDirectoryName(ReadOnlySpan<char>).
Declaration
public static string GetPathParent(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file or directory path to examine. May be absolute or relative. |
Returns
| Type | Description |
|---|---|
| string | The parent directory portion of |
GetPathRoot(string)
Returns the root portion of the specified path (e.g., C:</code> on Windows
or / on Unix), equivalent to GetPathRoot(ReadOnlySpan<char>).
Declaration
public static string GetPathRoot(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The absolute or relative path to examine. |
Returns
| Type | Description |
|---|---|
| string | The root directory component of |
See Also
IsAbsolutePath(string)
Determines whether the specified path is rooted (absolute), equivalent to IsPathRooted(ReadOnlySpan<char>).
Declaration
public static bool IsAbsolutePath(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to examine. |
Returns
| Type | Description |
|---|---|
| bool | true if |
See Also
IsRootPath(string)
Determines whether the specified path is exactly a file system root
(e.g., "C:" on Windows or "/" on Unix) rather than a
path that merely has a root prefix.
Declaration
public static bool IsRootPath(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to examine. |
Returns
| Type | Description |
|---|---|
| bool | true when |
See Also
IsValidPath(string)
Determines whether a path string is non-empty and contains only characters that are legal in file system paths on the current platform.
Declaration
public static bool IsValidPath(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path string to validate. |
Returns
| Type | Description |
|---|---|
| bool | true if |
Remarks
This method only validates the character set. It does not verify that the path actually exists or that the caller has the necessary permissions. For existence checks, use Exists(string) or DirectoryExists(string).
See Also
NormalizePath(string)
Normalizes all directory separator characters in a path to the
platform-specific DirectorySeparator, and removes any
trailing separator character unless the path is a root (e.g., C:</code>
or /).
Declaration
public static string NormalizePath(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to normalize. Both backslash and forward-slash variants are replaced. |
Returns
| Type | Description |
|---|---|
| string | The normalized path. Returns the original value unchanged when
|
See Also
ToBackSlashes(string)
Converts all forward slash directory separators in a path to backslashes, producing a Windows-native path string.
Declaration
public static string ToBackSlashes(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to convert. |
Returns
| Type | Description |
|---|---|
| string | The path with all forward slashes replaced by backslashes. Returns the
original value unchanged when |
See Also
ToForwardSlashes(string)
Converts all backslash directory separators in a path to forward slashes, making the path safe for use in URLs, Unity asset paths, and Unix-style APIs.
Declaration
public static string ToForwardSlashes(this string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to convert. |
Returns
| Type | Description |
|---|---|
| string | The path with all backslashes replaced by forward slashes. Returns the
original value unchanged when |
See Also
ToSafeFileName(string, char)
Replaces every character in fileName that is illegal on
the current platform with the specified replacement character,
producing a file name that can safely be used without throwing an I/O exception.
Declaration
public static string ToSafeFileName(this string fileName, char replacement = '_')
Parameters
| Type | Name | Description |
|---|---|---|
| string | fileName | The raw file name (without directory path) to sanitize. Must not include directory separator characters; those would also be treated as invalid and replaced. |
| char | replacement | The character to substitute for each illegal character. Defaults to
|
Returns
| Type | Description |
|---|---|
| string | A new string with all illegal characters replaced. Returns the original
string unchanged when |