我想在PowerShell脚本中将路径转换为相对路径。如何使用PowerShell实现?
例如:
例如:
Path to convert: c:\documents\mynicefiles\afile.txt
Reference path: c:\documents
Result: mynicefiles\afile.txt
而且
Path to convert: c:\documents\myproject1\afile.txt
Reference path: c:\documents\myproject2
Result: ..\myproject1\afile.txt
Resolve-Path
抛出异常(取决于$ErrorActionPreference
),当前位置也将被恢复,请使用try/catch包装代码:try{ push-location $root; resolve-path -relative $current } finally{ pop-location }
。 - zett42