Method pathname.normalize
Overload
Makes normal full path from path that can contain special substrings etc.
public static string normalize(string path, string defaultParentDirectory = null, PNFlags flags = 0)
Parameters
|
path (string)
Any path. |
|
defaultParentDirectory (string)
If path is not full path, combine it with defaultParentDirectory to make full path. |
| flags (PNFlags) |
Returns
Exceptions
|
ArgumentException
path is not full path, and defaultParentDirectory is not used or does not make it full path. |
Remarks
The sequence of actions:
- If path starts with
'%'character, expands environment variables and special folder names. See pathname.expand. - If path is not full path but looks like URL, and used flag CanBeUrl, returns path.
- If path is not full path, and defaultParentDirectory is not
null/"", combines path withexpand(defaultParentDirectory). - If path is not full path, throws exception.
- If path is like
"C:"makes like"C:\". - Calls API GetFullPathName. It replaces
'/'with'\\', replaces multiple'\\'with single (where need), processes@"\.."etc, trims spaces, etc. - If no flag DontExpandDosPath, if path looks like a short DOS path version (contains
'~'etc), calls API GetLongPathName. It converts short DOS path to normal path, if possible, for example@"c:\progra~1"to@"c:\program files". It is slow. It converts path only if the file exists. - If no flag DontRemoveEndSeparator, and string ends with
'\\'character, and length > 4, removes the'\\', unless then it would be a path to an existing file (not directory). - If no flag DontPrefixLongPath, calls pathname.prefixLongPathIfNeed, which adds
@"\\?\"etc prefix if path is very long.
Similar to System.IO.Path.GetFullPath. Main differences: this function expands environment variables, does not support relative paths (unless used defaultParentDirectory), trims '\\' at the end if need.