Class IOUtility
Static utility functions for file IO. These function are intended for unit test und sample in a solution code only.
public static class IOUtility
- Inheritance
-
IOUtility
- Inherited Members
Methods
EnsureAssets(string?, int?)
Ensures the assets folder exists in the solution root and an optional specified file or directory exists. If relativeFileOrDirectory is specified, it is considered to be a path to a directory if it ends with a directory separator. Otherwise, it is considered to ba a path to a file.
public static void EnsureAssets(string? relativeFileOrDirectory = null, int? requiredAssetsVersion = null)
Parameters
relativeFileOrDirectory
stringA relative path to a file or directory.
requiredAssetsVersion
int?The minimum of the required assets version.
EnsureAssetsVersion(int)
Ensures the assets directory exists in the solution root and its version is at least the specified version.
public static void EnsureAssetsVersion(int requiredAssetsVersion)
Parameters
requiredAssetsVersion
intThe minimum of the required assets version.
FindLatestTempFile(string?, string, string, bool)
Finds the latest temporary file in a directory. The pattern of the file is expected to be '{namePrefix}*_temp.{extension}'.
public static string? FindLatestTempFile(string? namePrefix, string path, string extension = "tmp", bool recursive = false)
Parameters
namePrefix
stringThe prefix of the file name to search for.
path
stringThe path to search in.
extension
stringThe file extension of the file.
recursive
boolIf set to
true
subdirectories are included in the search.
Returns
GetAssetsPath(string?)
Gets the root path of the current assets directory if no parameter is specified, or null, if no assets directory exists in the solution root directory. If a parameter is specified gets the assets root path combined with the specified relative path or file. If only the root path is returned it always ends with a directory separator. If a parameter is specified the return value ends literally with value of the parameter.
public static string? GetAssetsPath(string? relativePathOrFileInAsset = null)
Parameters
relativePathOrFileInAsset
string
Returns
GetSolutionRoot()
Gets the root path of the current solution, or null, if no parent directory with a solution file exists.
public static string? GetSolutionRoot()
Returns
GetTempFileName(string?, string?, bool)
Creates a temporary file name with the pattern '{namePrefix}-{WIN|WSL|LNX|...}-{...uuid...}_temp.{extension}'. The name ends with '_temp.' to make it easy to delete it using the pattern '*_temp.{extension}'. No file is created by this function. The name contains 10 hex characters to make it unique. It is not tested whether the file exists, because we have no path here.
public static string GetTempFileName(string? namePrefix, string? extension, bool addInfo = true)
Parameters
Returns
GetTempFullFileName(string?, string?, bool)
Creates a temporary file and returns the full name. The name pattern is '/.../temp/.../{namePrefix}-{WIN|WSL|LNX|...}-{...uuid...}_temp.{extension}'. The namePrefix may contain a sub-path relative to the temp directory. The name ends with '_temp.' to make it easy to delete it using the pattern '*_temp.{extension}'. The file is created and immediately closed. That ensures the returned full file name can be used.
public static string GetTempFullFileName(string? namePrefix, string? extension, bool addOS = true)
Parameters
Returns
GetTempPath(string?)
Gets the root or sub path of the current temp directory. The directory is created if it does not exist. If a valid path is returned it always ends with the current directory separator.
public static string? GetTempPath(string? relativeDirectoryInTemp = null)
Parameters
relativeDirectoryInTemp
string
Returns
GetViewerWatchDirectory()
Gets the viewer watch directory. Which is currently just a hard-coded directory on drive C or /mnt/c
public static string GetViewerWatchDirectory()
Returns
IsDirectorySeparator(char)
True if the given character is a directory separator.
public static bool IsDirectorySeparator(char ch)
Parameters
ch
char
Returns
NormalizeDirectorySeparators(ref string?)
Replaces all back-slashes with forward slashes in the specified path. The resulting path works under Windows and Linux if no drive names are included.
public static void NormalizeDirectorySeparators(ref string? path)
Parameters
path
string