Reputation: 4350
I want to find all the files having .zip extension in a folder (MyFiles) recursively and run the following command for each file in Windows PowerShell.
PS C:\solr-7.3.0> java -Dc=myCore1 -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar "File fullpath goes here"
Could you help me to achieve this?
Upvotes: 0
Views: 482
Reputation: 10044
Use the Get-ChildItem
cmdlet to find the relevant Zip files and then pipe the results to the ForEach-Object
cmdlet to loop over the files. The $_
or $psitem
variable is the current object passed through the pipeline. Then the FullName
property on that object will contain the full path to each Zip file.
Get-ChildItem -Path C:\Example\Path -Filter '*.zip' -Recurse |
ForEach-Object {
& java -Dc=myCore1 -Dauto=yes -Ddata=files -Drecursive=yes -jar example/exampledocs/post.jar $_.Fullname
}
Upvotes: 2