2012-11-13 48 views
1

在PowerShell中這個變量是路徑輪廓:它等於$Profile如何從Powershell中包含完全限定文件名的變量中獲取目錄名稱?

在我的系統:

C:\Users\Warren\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 

我希望得到公正的路徑部分:

C:\Users\Warren\Documents\WindowsPowerShell\ 

在C#你會打電話給Path.GetDirectoryName,所以我想我可以打電話[system.io.Path]::GetDirectoryName($fileName),但我想知道是否有一個內建的路徑操作系統,我應該知道在PowerShell中?

這是人們在做什麼?

[system.io.Path]::GetDirectoryName($Profile) 

回答

3

使用Split-Path的cmdlet:

Split-Path $PROFILE -Parent 
+0

'-Parent'可以在這種情況下可以省略。 –

+0

正確的我只是想顯示完整的語法,-parent是默認行爲 –

相關問題