PathUtil::Normalize Method (String^)

Visual Studio 2015
 

Returns a normalized form of the given path.

Namespace:   Microsoft.VisualStudio.PlatformUI
Assembly:  Microsoft.VisualStudio.Utilities (in Microsoft.VisualStudio.Utilities.dll)

public:
static String^ Normalize(
	String^ path
)

Parameters

path
Type: System::String^

Path to normalize.

Return Value

Type: System::String^

Normalized from path.

What it does:

  • Takes pains not to allocate extra temporary strings

  • Verifies that the path contains no invalid path characters, throwing an exception if any invalid characters are found

  • Strips leading and trailing whitespace

  • Replaces "/" with "\"

  • Replaces multiple consecutive "\" with a single "\", except for the leading "\\" of a UNC path

  • Removes the trailing "\", unless it's part of a root (e.g. "C:\")

  • Converts to lowercase

What it doesn't do:

  • Fully qualify a non-rooted filename (e.g. "dir\filename.ext")

  • Simplify relative pathnames (e.g. "C:\dir\..\FileInDriveRoot.ext"). It's tempting to use Path.GetFullPathName to perform this function, but that would entail an expensive trip to the disk or network.

  • Verify that the path exists.

Return to top
Show: