Convert-Path
將路徑從 PowerShell 路徑轉換為 PowerShell 提供者路徑。
語法
Convert-Path
[-Path] <String[]>
[<CommonParameters>]
Convert-Path
-LiteralPath <String[]>
[<CommonParameters>]
Description
Cmdlet 會將 Convert-Path
路徑從 PowerShell 路徑轉換成 PowerShell 提供者路徑。
範例
範例 1:將工作目錄轉換為標準檔案系統路徑
本範例會將以點 (.
) 表示的目前工作目錄轉換成標準 FileSystem 路徑。
PS C:\> Convert-Path .
C:\
範例 2:將提供者路徑轉換為標準登錄路徑
此範例會將PowerShell提供者路徑轉換成標準登錄路徑。
PS C:\> Convert-Path HKLM:\Software\Microsoft
HKEY_LOCAL_MACHINE\Software\Microsoft
範例 3:將路徑轉換為字串
這個範例會將路徑轉換為目前提供者的主目錄,也就是 FileSystem 提供者,轉換為字串。
PS C:\> Convert-Path ~
C:\Users\User01
範例 4:轉換隱藏項目的路徑
根據預設, Convert-Path
不會傳回隱藏的專案。 這個範例會使用 Force 參數來尋找隱藏的專案。
Get-Item
命令會.git
確認資料夾已隱藏。 不使用 Convert-Path
Force 參數時,只會傳回可見的專案。
新增 Force 參數會傳回所有專案,包括隱藏的專案。
PS> Get-Item .git -Force
Directory: D:\Git\PS-Docs\PowerShell-Docs
Mode LastWriteTime Length Name
---- ------------- ------ ----
d--h- 9/25/2024 4:46 PM .git
PS> Convert-Path .git*
D:\Git\PS-Docs\PowerShell-Docs\.github
D:\Git\PS-Docs\PowerShell-Docs\.gitattributes
D:\Git\PS-Docs\PowerShell-Docs\.gitignore
PS> Convert-Path .git* -Force
D:\Git\PS-Docs\PowerShell-Docs\.git
D:\Git\PS-Docs\PowerShell-Docs\.github
D:\Git\PS-Docs\PowerShell-Docs\.gitattributes
D:\Git\PS-Docs\PowerShell-Docs\.gitignore
參數
-Force
允許 Cmdlet 取得使用者無法存取的專案,例如隱藏或系統檔案。 Force 參數不會覆寫安全性限制。 實作會因提供者而異。 如需詳細資訊,請參閱 about_Providers。
此參數已在 PowerShell 7.5-preview.5 中新增。
類型: | SwitchParameter |
Position: | Named |
預設值: | False |
必要: | False |
接受管線輸入: | False |
接受萬用字元: | False |
-LiteralPath
指定要轉換的路徑,做為字串陣列。 LiteralPath 參數的值會完全依照其類型一樣使用。 不會將任何字元解譯為通配符。 如果路徑包含逸出字元,請以單引弧括住它。 單引號會告知PowerShell不要將任何字元解譯為逸出序列。
如需詳細資訊,請參閱 about_Quoting_Rules。
類型: | String[] |
別名: | PSPath, LP |
Position: | Named |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | False |
-Path
指定要轉換的 PowerShell 路徑。
類型: | String[] |
Position: | 0 |
預設值: | None |
必要: | True |
接受管線輸入: | True |
接受萬用字元: | True |
輸入
您可以將路徑管線傳送至此 Cmdlet,但不能使用常值路徑。
輸出
此 Cmdlet 會傳回包含已轉換路徑的字串。
備註
PowerShell 包含下列的 Convert-Path
別名:
- 所有平臺:
cvpa
包含 Path 名詞的 Cmdlet 會操作路徑名稱,並以簡潔的格式傳回名稱,讓所有 PowerShell 提供者都能解譯。 其設計用於您想要以特定格式顯示路徑之所有或部分的程式和腳本中。 使用 它們就像使用 Dirname、 Normpath、 Realpath、 Join 或其他路徑操作工具一樣。
您可以使用路徑 Cmdlet 搭配數個提供者,包括 FileSystem、 登錄和 憑證 提供者。
此 Cmdlet 的設計目的是要處理任何提供者所公開的數據。 若要列出工作階段中可用的提供者,請輸入 Get-PSProvider
。 如需詳細資訊,請參閱 about_Providers。
Convert-Path
只會轉換現有的路徑。 它無法用來轉換尚未存在的位置。