Table of Contents

Class PathUtil

Namespace
Hi.Common.PathUtils
Assembly
HiGeom.dll

Utility class for path manipulation and management.

public static class PathUtil
Inheritance
PathUtil
Inherited Members

Fields

DotAlterWord

Constant used to replace dots in HTTP string parameters.

public const string DotAlterWord = "-(dot)-"

Field Value

string

Methods

Combine(string, string)

Combines a base path with a subpath, ensuring consistent directory separators.

public static string Combine(string basePath, string subPath)

Parameters

basePath string

The base path

subPath string

The subpath to append

Returns

string

The combined path with forward slashes as directory separators, or null if basePath is null

Combine(params string[])

Combines multiple path segments, ensuring consistent directory separators.

public static string Combine(params string[] paths)

Parameters

paths string[]

The path segments to combine

Returns

string

The combined path with forward slashes as directory separators

CombineAsSubDirectory(string, string, string)

Combines a base directory with a relative file path and appends a suffix to derive a sub-directory path. The suffix is only appended when relFile is not null or whitespace.

public static string CombineAsSubDirectory(string baseDirectory, string relFile, string suffixIfAdded = "-src")

Parameters

baseDirectory string

The base directory.

relFile string

The relative file path.

suffixIfAdded string

The suffix appended to the combined path when relFile is not null or whitespace.

Returns

string

The combined sub-directory path with forward slashes as directory separators.

GetConcatedDirectoryName(string, string)

Gets the directory name from a combined base directory and relative file path.

public static string GetConcatedDirectoryName(string baseDirectory, string relFile)

Parameters

baseDirectory string

The base directory

relFile string

The relative file path

Returns

string

The directory name of the combined path with forward slashes as directory separators

GetDirectoryName(string)

Gets the directory name of a path, ensuring consistent directory separators.

public static string GetDirectoryName(string path)

Parameters

path string

The path to get the directory name from

Returns

string

The directory name with forward slashes as directory separators, or null if the path has no directory component

GetParentIgnoreTailSlash(string)

Gets the parent directory of a path, ignoring any trailing slashes.

public static string GetParentIgnoreTailSlash(this string path)

Parameters

path string

The path to get the parent of

Returns

string

The parent directory path

GetPathByTemplate(string, string, string, string)

Generates a path by replacing keywords in a template path.

public static string GetPathByTemplate(string templatePath, string replacingPath, string replacedPathKeyword, string replacedNameKeyword)

Parameters

templatePath string

The template path containing keywords to be replaced

replacingPath string

The path to use as replacement

replacedPathKeyword string

The path keyword to be replaced in the template

replacedNameKeyword string

The name keyword to be replaced in the template

Returns

string

The processed path with keywords replaced

GetRelativePath(string, string)

Gets the relative path from one path to another, ensuring consistent directory separators.

public static string GetRelativePath(string relativeTo, string path)

Parameters

relativeTo string

The path that is the reference point

path string

The path to which the relative path is calculated

Returns

string

The relative path with forward slashes as directory separators

GetRelativePathIfIsDescendant(string, string)

Gets the relative path if the target path is a descendant of the reference path; otherwise, returns the original path.

public static string GetRelativePathIfIsDescendant(string relativeTo, string path)

Parameters

relativeTo string

The path that is the reference point

path string

The path to which the relative path is calculated

Returns

string

The relative path if path is a descendant of relativeTo; otherwise, the original path. Forward slashes are used as directory separators in either case.

IsDescendant(DirectoryInfo, string)

Determines whether a path is a descendant of a specified directory.

public static bool IsDescendant(this DirectoryInfo ascendentDirectory, string descendantPath)

Parameters

ascendentDirectory DirectoryInfo

The potential ancestor directory

descendantPath string

The path to check

Returns

bool

True if the path is a descendant of the directory; otherwise, false

IsDescendant(string, string)

Determines whether a path is a descendant of a specified directory.

public static bool IsDescendant(string ascendentDirectory, string descendantPath)

Parameters

ascendentDirectory string

The potential ancestor directory path

descendantPath string

The path to check

Returns

bool

True if the path is a descendant of the directory; otherwise, false

IsDescendantByRelPath(string, string)

Determines whether a path is a descendant of a specified directory using relative path calculation.

public static bool IsDescendantByRelPath(string ascendentDirectory, string descendantPath)

Parameters

ascendentDirectory string

The potential ancestor directory path

descendantPath string

The path to check

Returns

bool

True if the path is a descendant of the directory; otherwise, false

RemoveTailSlashIfExisted(string)

Removes the trailing slash or backslash from a path if it exists.

public static string RemoveTailSlashIfExisted(this string path)

Parameters

path string

The path to process

Returns

string

The path without a trailing slash or backslash

ReplaceDirectorySeparator(string)

Replaces backslashes with forward slashes in a path string.

public static string ReplaceDirectorySeparator(this string src)

Parameters

src string

The source path string

Returns

string

The path string with all backslashes replaced by forward slashes

ResolveSubDirectory(string, string, string)

Resolves the sub-directory for loading with legacy fallback. Returns the CombineAsSubDirectory(string, string, string) path if it exists; otherwise falls back to the legacy GetConcatedDirectoryName(string, string) path if it exists; otherwise defaults to the CombineAsSubDirectory(string, string, string) path.

public static string ResolveSubDirectory(string baseDirectory, string relFile, string suffix = "-src")

Parameters

baseDirectory string

The base directory.

relFile string

The relative file path.

suffix string

The suffix for the new sub-directory path.

Returns

string

The resolved sub-directory path with forward slashes as directory separators.