Home > Enterprise >  What is the PowerShell equivalent for a Windows Command Processor FOR loop searching for files match
What is the PowerShell equivalent for a Windows Command Processor FOR loop searching for files match

Time:02-05

I have this Windows command line in a batch file:

for %%f in (*fla) do fla2comp.exe -d "%%f"

How does the command line look in PowerShell syntax?

fla2comp.exe is in the directory of the batch file.

CodePudding user response:

To resolve all files in the current folder matching the wildcard name *fla:

Get-ChildItem -File -Filter *fla

To loop through each file, pipe the output to the ForEach-Object cmdlet:

Get-ChildItem -File -Filter *fla |ForEach-Object { <# $_ will contain a reference to each file here #>}

Then pass the FullName property (it'll contain the rooted file path) of each file object to fla2comp.exe:

Get-ChildItem -File -Filter *fla |ForEach-Object {
    fla2comp.exe -d $_.FullName
}
  •  Tags:  
  • Related