【问题标题】:Running an exe in recursive folders在递归文件夹中运行 exe
【发布时间】:2015-11-21 17:43:11
【问题描述】:
Set-ExecutionPolicy Unrestricted
$start_path ="D:\VST\"
$start_path> Get-ChildItem-Recurse |
foreach { cd $_.DirectoryName; "VST_Screenshot_Tool"; cd ..; }

这应该在根目录和$start_path 的所有子文件夹中运行VST_Screenshot_Tool.exe。我收到此错误:

Expressions are only allowed as the first element of a pipeline.
At C:\Users\pithy\Desktop\screenshotter.ps1:2 char:13
+ $start_path  <<<< ="D:\ZZ_AUDIO\VST etc\__ARCHIVE\*" |
    + CategoryInfo          : ParserError: (:) [],       ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline

任何指针将不胜感激。

【问题讨论】:

    标签: powershell windows-7


    【解决方案1】:

    $start_path&gt; Get-ChildItem-Recurse 会将字符串D:\VST\ 写入当前目录中的文件Get-ChildItem-Recurse。此外,您需要呼叫操作员 (&amp;) 来执行命令字符串,如果您想运行外部命令,您应该包含扩展名。如果没有操作符,PowerShell 将简单地回显字符串。

    将您的代码更改为:

    $start_path = 'D:\VST'
    
    Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {
      Set-Location $_.FullName
      & "VST_Screenshot_Tool.exe"
    }
    

    在 PowerShell v2 及更早版本上,您需要像这样替换 -Directory 参数:

    Get-ChildItem $start_path -Recurse | Where-Object {
      $_.PSIsContainer
    } | ForEach-Object {
      Set-Location $_.FullName
      & "VST_Screenshot_Tool.exe"
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-06
      • 1970-01-01
      • 2011-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 2014-12-22
      • 2017-01-30
      • 1970-01-01
      相关资源
      最近更新 更多