Search notes:

PowerShell module filesystem: resolve-relativePath

The function resolve-relativePath of the module filesystem returns the relative path between a directory and a file or directory.
Thus, it improves the functionality provided by the built-in cmdlet resolve-path which only allows to get the relative path from the current directory ($pwd).
resolve-relativePath $fromDir  $destPath
Note: $fromDir and $destPath must share a common prefix in order for the function to succeed.
This function was inspired (and copied with minor adaptions) by/from Carbon's command Resolve-RelativePath.
The function uses the WinAPI function PathRelativePathTo.

Simple example

$sql_file_root = 'P:\ath\to\development\sql'

foreach ($file in get-childItem $sql_file_root -recurse -include *.sql) {

    $rel_path = resolve-relativePath $sql_file_root $file
    $rel_path

}

Passing an array to the second parameter

The second parameter accepts an array:
PS:> resolve-relativePath  x/y  x/a/b, x/y/z, x/
..\a\b
.\z
..\

Index