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

CombineWithFolderExtension(string, string)

Combines a base directory with a relative file path, preserving the folder structure.

public static string CombineWithFolderExtension(string baseDirectory, string relFile)

Parameters

baseDirectory string

The base directory

relFile string

The relative file path

Returns

string

The combined path with forward slashes as directory separators

CombineWithoutExtension(params string[])

Combines multiple path segments and removes the file extension from the result.

public static string CombineWithoutExtension(params string[] paths)

Parameters

paths string[]

The path segments to combine

Returns

string

The combined path without file extension, using forward slashes as directory separators

GetCombinedDirectoryName(string, string)

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

public static string GetCombinedDirectoryName(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 replacedPathKeyword, string replacedNameKeyword, string replacingPath)

Parameters

templatePath string

The template path containing keywords to be replaced

replacedPathKeyword string

The path keyword to be replaced in the template

replacedNameKeyword string

The name keyword to be replaced in the template

replacingPath string

The path to use as replacement

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