我想將路徑轉換爲PowerShell腳本中的相對路徑。 如何使用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
您也可以使用Push-Location和Pop-Location來設置位置,然後恢復到其原始值,而不是使用臨時變量。相同的基本解決方案,但沒有臨時變量。 –