PathCommonPrefix (shlwapi)
Last changed: -85.75.12.132

.
Summary
Compares two paths to determine if they share a common prefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".

C# Signature:

public static extern Int32 PathCommonPrefix(
    [In] String pszFile1,
    [In] String pszFile2,
    [Out] StringBuilder pszPath
    );
const Int32 MAX_PATH = 260;

VB Signature:

Declare Function PathCommonPrefix Lib "shlwapi.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

StringBuilder str = new StringBuilder(MAX_PATH);
Int32 nRet = PathCommonPrefix(
    @"C:\win\desktop\temp.txt",
    @"c:\win\tray\sample.txt",
    str
    );
// Result: nRet == 6 && str.ToString() == @"C:\win"

Alternative Managed API:

Do you know one? Please contribute it!

Documentation