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.
It seems that the returned value of PathRelativePathTo always starts with a dot.

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
..\

Quirk

The function currently calls PathRelativePathTo with the Directory attribute for the $fromDir and the Normal (File) attribute for $destPath.
Thus, when going from a directory to another, the function returns a somewhat quirky result (..\.. would already be ok):
PS: 32 C:/Users/igsnyre/a/b/c/d> resolve-relativePath   a/b/c/d   a/b
..\..\..\b
This behavior should probably be changed once.

PowerShell 7

In PowerShell 7 (Netstandard 2.1?), relative paths can apparently be queried like so:
[System.IO.DirectoryInfo]$x = './a/b/c/d'
[System.IO.DirectoryInfo]$y = './a/b/x/y'
[System.IO.Path]::GetRelativePath($x,$y)

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758207167, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/modules/personal/filesystem/resolve-relativePath/index(90): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78