Reputation: 2460
Very beginner question, but I'd appreciate some help with it.
I have a folder. I have a function, improve
. I want to apply that function to every file within the folder. I've Googled this simple problem but none of the solutions I've found seem to work. What do I do?
Upvotes: 0
Views: 72
Reputation: 52609
Something like this -
dir -path C:\stuff | ForEach-Object {improve $_}
If you make your function support object piping then you can do this -
dir -path C:\stuff | improve
Here's a simple example how to do that -
function improve ($FileItem) {
process {
if ($_) {$FileItem = $_}
Write-Host $FileItem
}
}
Upvotes: 2