【问题标题】:How to start .bat files which i just collected out of a folder如何启动我刚刚从文件夹中收集的 .bat 文件
【发布时间】:2013-08-02 06:07:54
【问题描述】:

当我从这样的特定文件夹中找到带有get-childitems.bat 文件时:

$bats = Get-ChildItem "C:\Projects\PSScripts\batfiles"

foreach ($bat in $bats) 
{
  start-process  
}

如何让它们运行?启动过程不起作用

谢谢

【问题讨论】:

    标签: powershell batch-file powershell-2.0


    【解决方案1】:

    试试这个:

    get-childitem . | foreach-object { start-process -filepath $_ }
    

    显然,不要使用点,而是使用您的目录路径。

    首先,您使用 get-childitem 获取所有文件,然后使用管道将结果传递给 foreach 对象。 $_ 代表当前迭代中的变量。

    如果你想使用你的脚本块,应该是这样的:

    $bats = Get-ChildItem "C:\Projects\PSScripts\batfiles"
    
    foreach ($bat in $bats) 
    {
      start-process -filepath $bat
    }
    

    【讨论】:

    • 我想我需要更多的练习。我不能让它像这样运行:(
    【解决方案2】:

    只需这样做:

    Get-ChildItem 'C:\Projects\PSScripts\batfiles' -Filter '*.bat' | % {
      & $_.FullName
    }
    

    【讨论】:

    • 我看不出我的建议对Get-ChildItem 不起作用。请详细说明。
    • 当然是我的错。抱歉 :) 2 小时前我误读了一些东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 2021-12-10
    • 2017-12-03
    相关资源
    最近更新 更多