Function Reference


_WinAPI_PathRelativePathTo

Creates a relative path from one file or folder to another

#include <WinAPIShPath.au3>
_WinAPI_PathRelativePathTo ( $sPathFrom, $bDirFrom, $sPathTo, $bDirTo )

Parameters

$sPathFrom The path to the file or directory that defines the start of the relative path.
$bDirFrom Specifies whether is $sPathFrom path to the directory, valid values:
    True - Directory.
    False - File.
$sPathTo The path to the file or directory that defines the endpoint of the relative path.
$bDirTo Specifies whether is $fDirTo path to the directory, valid values:
    True - Directory.
    False - File.

Return Value

Success: The relative path.
Failure: Empty string.

Remarks

This function takes a pair of paths and generates a relative path from one to the other. The paths do not have
to be fully-qualified, but they must have a common prefix, otherwise, the function fails.

For example, let the starting point, $sPathFrom, be "C:\A\B\C", and the ending point, $sPathTo, be "C:\A\D".
_WinAPI_PathRelativePathTo() will return the relative path from $sPathFrom to $sPathTo as: "..\..\D\E". You will
get the same result if you set $sPathFrom to "\A\B\C" and $sPathTo to "\A\D\E". On the other hand, "C:\A\B\C"
and "D:\A\D" do not share a common prefix, and the function will fail. Note that "\" is not considered a prefix
and is ignored. If you set $sPathFrom to "\\A\B\C", and $sPathTo to "\\C\D", the function will fail.

See Also

Search PathRelativePathTo in MSDN Library.

Example

#include <WinAPIShPath.au3>

Local $sPath = _WinAPI_PathRelativePathTo(@ScriptDir, 1, @ScriptDir & "\..", 1)

ConsoleWrite('Relative path: ' & $sPath & @CRLF)

If $sPath Then
        ShellExecute($sPath)
EndIf