2009-07-25 21 views
46

Bunu PowerShell'de nasıl yaparım. Bir toplu dosyasında yapardım: % ~ PowerShell 3.0 kullanıcıları için d0% ~ p0Yürütülmekte olan powershell komut dosyasının yolu

+0

Dup: http://stackoverflow.com/questions/801967/how-can-i-find-the-source-path-of-an-executing-script –

+2

tarafından şekilde,% ~ dp0 –

cevap

30
Get-ScriptDirectory to the Rescue blog girdisinde itibaren

...

function Get-ScriptDirectory 
{ 
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value 
    Split-Path $Invocation.MyCommand.Path 
} 
+1

'a kısaltabilirsiniz. Ayrıca kopyadaki yanıta bakın: http://stackoverflow.com/a/6985381/60620 –

9
split-path $SCRIPT:MyInvocation.MyCommand.Path -parent 

Bill

30

- Her iki modülleri için işler şu ve komut dosyaları:

function Get-ScriptDirectory { 
    Split-Path -parent $PSCommandPath 
} 
-11

In powershell 2.0

bölünmüş yol $ pwd

+3

Wroking dizini komut dizileriyle aynı değildir. – majkinetor

İlgili konular