TriLib
Search Results for

    Show / Hide Table of Contents

    Class FileUtils

    Represents a series of file utility methods.

    Inheritance
    object
    FileUtils
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    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 basePath; false to search only in basePath.

    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 filename is null or empty.

    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 path is null or empty.

    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 filename is null or empty. If the file has no extension, returns filename itself.

    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 filename is null or empty.

    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 filename is null, empty, or an exception occurs while reading the file.

    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 filename is null, empty, or an exception occurs.

    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 path is null or empty.

    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 inputData before writing it to disk. If null, the data is written directly to the file.

    Returns
    Type Description
    bool

    true if the file was successfully saved (or already exists in the target location); false otherwise.

    In this article
    Back to top Generated by DocFX