Click or drag to resize

PathComparer Class

Provides Equals and Compare operations for strings which represent filesystem paths. Paths can be null, relative or rooted, local or UNC, can contain long names or shortened 8.3 names. Paths can point to directory or file, existing or not (but see Remarks). This class implements IComparer{string} and can be used as a comparer for hash- or comparator-based collections (like Dictionary{string, T} where paths are keys) or algorithms which store or operate on file system paths.
Inheritance Hierarchy
SystemObject
  PDTec.IceNet.Sdk.UtilsPathComparer

Namespace:  PDTec.IceNet.Sdk.Utils
Assembly:  PDTec.IceNet.Sdk (in PDTec.IceNet.Sdk.dll) Version: 7.2.0.0 (7.2.7583.15464)
Syntax
C#
public class PathComparer : IComparer<string>

The PathComparer type exposes the following members.

Constructors
  NameDescription
Public methodPathComparer
Initializes a new instance of the PathComparer class
Top
Methods
  NameDescription
Public methodCompare
Lexicographically compares two strings for relative order.
Public methodEquals(Object)
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEquals(String, String)
Compares two strings which represent file system paths for equality.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetHashCode(String)
Calculate hash code of a file system path.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberNormalize
Converts path to its normalized representation:
  • Converts relative path to absolute path, using current directory and current drive information
  • Replaces 'dot' path segments ('.' and '..') with appropriate directories
  • Converts directory separators to primary directory separator
  • Converts shortened 8.3 names to long names
  • Strips trailing directory separators
  • It's not required to normalize casing
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks
Path strings passed to functions of this class are normalized with GetFullPath(String) method, what causes following issues:
  • Before comparison is performed, relative paths are expanded to absolute ones, with regard to current working directory
  • '.' and '..' path entries are resolved appropriately
  • Target file or directory is not required to exists, but if it exists, sufficient permissions are required to access path information
  • If path contains shortened 8.3 names, they are expanded to long names only if file or directory specified by a path exists
Path strings are compared with case-insensitive, culture independent (ordinal-based) string comparer. This behaviour is not applicable for case-sensitive file systems.
See Also

Reference

PathGetFullPath(String)