I'm using windows 8 pro and want to do something I'm hoping is very simple. I just want to execute one program against all the files of a certain type in a directory. no trees, just in the flat directory. In Linux I would:
find . -name 'exec c:\user\local\bin\myprog {} \;
I've literally spend a couple hours wrestling with power shell, running into policy problems, permissions, etc. Is there some simple way I can make this happen?
PowerShell utilizes the “Get-ChildItem” command for listing files of a directory. The “dir” in the Windows command prompt and “Get-ChildItem” in PowerShell perform the same function. In this article, we have compiled examples to understand listing files in PowerShell.
To pass in multiple file names, you can list them comma-delimited in the command. This results in both directories a and b being copied into directory c .
This is easy but different than using find
e.g.:
Get-ChildItem -File | Foreach {c:\user\local\bin\myprog $_.fullname}
For doing stuff at the command line, aliases can make this a bit more terse:
ls -file | % {c:\user\local\bin\myprog $_.fullname}
PowerShell prefers commands that are narrow in focus but that can be composed together in a pipeline to provide lots of capability. Also, PowerShell pipes .NET objects e.g. Get-ChildItem pipes System.IO.FileInfo objects. You can then use commands like Foreach, Where, Select, Sort, Group, Format to manipulate the objects passed down the pipeline. If you have time, I recommend you checking out my free ebook Effective PowerShell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With