![](/img/trans.png)
[英]How to run specific commands/functions of Powershell from Command line?
[英]How to run powershell commands from command line to use current directory as a param?
在 powershell (從 windows 命令行運行),如果我這樣做
Get-Location
,它顯示了我當前的工作目錄。 如果我有這個命令
dir -Path "C:\Users\me\Documents\GitHub\project\src" -Filter bot.ts
它進行搜索。 但是如何用Get-Location
替換path
? 試了還是不行,好像是在找一個叫Get-Location的程序?
使用子表達式$()
Get-ChildItem -Path $(Get-Location).Path -Filter bot.ts
或者使用自動變量$PWD
PS C:\Users\Neko> $PWD
Path
----
C:\Users\Neko
PS C:\Users\Neko> $PWD.Path
C:\Users\Neko
所以
Get-ChildItem -Path $PWD.Path -Filter bot.ts
默認情況下Get-ChildItem
(與dir
和ls
相同)將在當前目錄中工作,因此Path
開關是不必要的。
Get-ChildItem -Filter bot.ts
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.