Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find all .bat files and execute them one by one?

I am still very new to PowerShell and need some help.

I have some .bat files in a folder called: c:\scripts\run\ and I want to run them one by one but I don't know how many I have, it changes from time to time.

So I want to run a loop with foreach like this:

foreach ($file in get-childitem c:\scripts\run | where {$_.extension -eq ".bat"})

But I don't know how to run them now. I know that I can run them 1 by 1 like this :

./run1.bat
./run2.bat
./run3.bat

But how do I implement that? Thanks!!

like image 588
RayofCommand Avatar asked Dec 11 '22 12:12

RayofCommand


1 Answers

Try this:

Get-Childitem -Path c:\scripts\run -Filter *.bat | % {& $_.FullName}
like image 164
Dave Sexton Avatar answered Dec 23 '22 14:12

Dave Sexton