简体   繁体   中英

Execute 'where' command in cmd with PowerShell Studio

I've just tried to exec this command, and works, but I want to know if there is a way to cut the path printed. This is the doc page I read, an this is what it prints

"C:\Users\user\Downloads\NSClient v67.msi"

I want only the path, without the filename, something like "C:\Users\bryanar\Downloads\" so I can cd to that path and exec the.msi

Any ideas?

14:10:31.27  C:\src
>FOR %A IN ("C:\Users\user\Downloads\NSClient v67.msi") DO (ECHO "%~dpA")

14:10:33.30  C:\src
>(ECHO "C:\Users\user\Downloads\" )
"C:\Users\user\Downloads\"

In a.bat file script, double the % character on the loop variable.

FOR %%A IN ("C:\Users\user\Downloads\NSClient v67.msi") DO (ECHO "%%~dpA")

Doing this in PowerShell is easy as well.

$thedir = (Get-ChildItem "$Env:USERPROFILE\Downloads\NSClient v67.msi").Directory.ToString()
$thedir = (Get-ChildItem "C:\Users\user\Downloads\NSClient v67.msi").Directory.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM