我正在搜索文件夹,以便找到包含我想要的内容的文件夹。
$path = dir "C:\windows\ccmcache\*\Office.en-us" -Directory
echo $path
它返回:
Directory: C:\windows\ccmcache\c
但是当我运行我的命令时:
Start-Process "$path\setup.exe /uninstall ProPlus /config Uninstall.xml" -Wait
它尝试运行:
C:\windows\ccmcache\c\Office.en-us\setup.exe............
这不存在!那么我怎样才能后退一步,以便从 c
文件夹 运行 setup.exe
命令?
像这样的东西:
$path2 = $path\cd..
提前谢谢大家。
最佳答案
你可以简单地做:
$Path2 = Resolve-Path (Join-Path $Path '..')
备注:
Join-Path
是连接路径字符串的跨平台方式Resolve-Path
将为您提供完全限定的路径名- ^^ 步骤是可选的,因为 Windows 将为您遍历
..
,但它有助于直观地查看它解析到的文件夹。
- ^^ 步骤是可选的,因为 Windows 将为您遍历
这有帮助吗?
关于windows - 如何使用 Powershell 在路径中后退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45240480/