Show / Hide Table of Contents

Class pathname

File path string functions. Parse, combine, make full, make unique, make valid, expand variables, etc.

public static class pathname
Remarks

Most functions of this class work with strings and don't access the file system. Several functions query file system info.

Functions of this class don't throw exceptions when path is invalid (path format, invalid characters). Only pathname.normalize throws exception if not full path.

Also you can use .NET class System.IO.Path. In its documentation you'll find more info about paths.


Namespace: Au
Assembly: Au.dll
Inheritance
object
pathname

Fields

Name Description
maxDirectoryPathLength

Maximal directory path length supported by all functions (native, .NET and this library). For longer paths need @"\\?\" prefix. It is supported by most native kernel API (but not shell API) and most functions of this library and .NET.

maxFilePathLength

Maximal file (not directory) path length supported by all functions (native, .NET and this library). For longer paths need @"\\?\" prefix. It is supported by most native kernel API (but not shell API) and most functions of this library and .NET.

Methods

Name Description
combine(string, string, bool, bool)

Combines two path parts using character '\\'. For example directory path and file name.

correctName(string, string)

Replaces characters that cannot be used in file names.

expand(string, bool?)

If path starts with "%" or "\"%", expands environment variables enclosed in %, else just returns path. Also supports known folder names, like "%folders.Documents%". More info in Remarks.

findExtension(ReadOnlySpan<char>)

Finds filename extension, like ".txt".

getDirectory(string, bool)

Removes filename part from path. By default also removes separator ('\\' or '/') if it is not after drive name (eg "C:").

getExtension(string)

Gets filename extension, like ".txt".

getExtension(string, out string)

Gets filename extension and path part without the extension. More info: getExtension(string).

getName(string)

Gets filename from path. Does not remove extension.

getNameNoExt(string)

Gets filename without extension.

getRootLength(ReadOnlySpan<char>)

Gets the length of the drive or network folder part in path, like @"C:\", @"\\server\share\", @"\\?\C:\", @"\\?\UNC\server\share\", etc.

getUrlProtocolLength(ReadOnlySpan<char>)

Gets the length of the URL protocol name (also known as URI scheme) in string, including ':'. If the string does not start with a protocol name, returns 0.

isFullPath(ReadOnlySpan<char>, bool)

Returns true if the string is full path, like @"C:\a\b.txt" or @"C:" or @"\\server\share\...":

isFullPathExpand(string, out string, bool?)

Expands environment variables and calls/returns pathname.isFullPath.

isFullPathExpand(ref string, bool?)

Expands environment variables and calls/returns pathname.isFullPath.

isInvalidName(string)

Returns true if name cannot be used for a file name, eg contains '\\' etc characters or is empty. More info: pathname.correctName.

isInvalidNameChar(char)

Returns true if character c is invalid in file names (the filename part).

isInvalidPathChar(char)

Returns true if character c is invalid in file paths.

isUrl(ReadOnlySpan<char>)

Returns true if the string starts with a URL protocol name (existing or not) and ':' character. Calls pathname.getUrlProtocolLength and returns true if it's not 0.

makeUnique(string, bool)

Creates path with unique filename for a new file or directory. If the specified path is of an existing file or directory, returns path where the filename part is modified like "file 2.txt", "file 3.txt" etc. Else returns unchanged path.

normalize(string, string, PNFlags)

Makes normal full path from path that can contain special substrings etc.

prefixLongPath(string)

If path is full path (see pathname.isFullPath) and does not start with @"\\?\", prepends @"\\?\". If path is network path (like @"\\computer\folder\..."), makes like @"\\?\UNC\computer\folder\...".

prefixLongPathIfNeed(string)

Calls pathname.prefixLongPath if path is longer than pathname.maxDirectoryPathLength (247).

unprefixLongPath(string)

If path starts with @"\\?\" prefix, removes it. If path starts with @"\\?\UNC\" prefix, removes @"?\UNC\".