pathrelativepathto (shlwapi)
Last changed: -165.225.80.101

.
Summary
Creates a relative path from one file or folder to another.

C# Signature:

[DllImport("shlwapi.dll")]
public static extern Int32 PathRelativePathTo(
     [Out] StringBuilder pszPath,
     [In] String pszFrom,
     [In] UInt32 dwAttrFrom,
     [In] String pszTo,
     [In] UInt32 dwAttrTo
);
const UInt32 FILE_ATTRIBUTE_DIRECTORY = 0x10;
const Int32 MAX_PATH = 260;

VB Signature:

Declare Function PathRelativePathTo 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);
UInt32 dwAttr1, dwAttr2;
dwAttr1 = FILE_ATTRIBUTE_DIRECTORY;
dwAttr2 = 0;
Int32 nRet = PathRelativePathTo(
     str,
     @"c:\a\b\path", dwAttr1,
     @"c:\a\x\y\file", dwAttr2
     );
// Result: str.ToString() == @"..\..\x\y\file"

Alternative Managed API:

Do you know one? Please contribute it!

Documentation