Class FileUtils
Represents a series of file utility methods.
Inherited Members
Namespace: TriLibCore.Utils
Assembly: TriLibCore.dll
Syntax
public static class FileUtils
Methods
FindFile(string, string, bool)
Tries to find a file with the specified originalPath starting from the given basePath.
Declaration
public static string FindFile(string basePath, string originalPath, bool recursively = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | basePath | The base directory to begin the search. |
| string | originalPath | The relative or absolute path of the file to find. |
| bool | recursively | true to search within all subdirectories of |
Returns
| Type | Description |
|---|---|
| string | The fully qualified path to the file if it is found; otherwise, null. |
GetFileDirectory(string)
Gets the directory portion of the specified filename.
Declaration
public static string GetFileDirectory(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The full path from which to extract the directory. |
Returns
| Type | Description |
|---|---|
| string | The directory portion of the path, or null if none is found or |
GetFileExtension(string, bool)
Gets the file extension from the specified path.
Declaration
public static string GetFileExtension(string path, bool includeDot = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path to process. |
| bool | includeDot | true to include the dot (.) in the returned extension; false to exclude it. |
Returns
| Type | Description |
|---|---|
| string | The file extension in lowercase, or null if none is found. |
GetFilename(string)
Retrieves the file name from the given path.
Uses GetFileName(string) for the underlying operation,
but falls back to string manipulation if the result matches the entire path.
Declaration
public static string GetFilename(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The full file path. |
Returns
| Type | Description |
|---|---|
| string | The file name portion of the path, or null if |
GetFilenameWithoutExtension(string)
Gets the file name (without the extension) from the specified filename.
Declaration
public static string GetFilenameWithoutExtension(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The full path from which to extract the file name without extension. |
Returns
| Type | Description |
|---|---|
| string | The file name without extension, or null if |
GetShortFilename(string)
Gets the file name (including its extension) from the specified filename.
Declaration
public static string GetShortFilename(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The full path from which to extract the short file name. |
Returns
| Type | Description |
|---|---|
| string | The short file name (with extension), or null if |
LoadFileData(string)
Synchronously loads all file data from the specified filename.
Declaration
public static byte[] LoadFileData(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The full path to the file to read. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array containing the file data, or an empty array if |
LoadFileStream(string)
Creates and returns a FileStream for the specified filename.
Declaration
public static FileStream LoadFileStream(string filename)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The full path of the file to open. |
Returns
| Type | Description |
|---|---|
| FileStream | A FileStream in Open mode with read-only access,
or null if |
SanitizePath(string)
Normalizes a file path by removing invalid filename characters and replacing backslashes with forward slashes.
Declaration
public static string SanitizePath(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The original path. |
Returns
| Type | Description |
|---|---|
| string | The sanitized path, or null if |
TrySaveFileAtPersistentDataPath(AssetLoaderContext, string, string, IEnumerator<byte>, out string, Action<IEnumerator<byte>, string>)
Attempts to save an embedded file to persistent storage, optionally decoding its data.
Declaration
public static bool TrySaveFileAtPersistentDataPath(AssetLoaderContext assetLoaderContext, string objectName, string filename, IEnumerator<byte> inputData, out string finalPath, Action<IEnumerator<byte>, string> decoder = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AssetLoaderContext | assetLoaderContext | An AssetLoaderContext containing context information for the asset loading process. |
| string | objectName | The name of the object associated with the embedded file. |
| string | filename | The name of the embedded file. |
| IEnumerator<byte> | inputData | An IEnumerator<T> that yields the raw file data, byte by byte. |
| string | finalPath | When this method returns true, contains the path where the file was saved; otherwise, null. |
| Action<IEnumerator<byte>, string> | decoder | An optional action that can decode the |
Returns
| Type | Description |
|---|---|
| bool | true if the file was successfully saved (or already exists in the target location); false otherwise. |