Reputation: 984
Why is
dir E:\Music -File -Exclude *.mp3 -Recurse | foreach {del $_.FullName}
not working? I tested all the possibilities I could think of and it is still not working.
Thanks in advance.
Upvotes: 6
Views: 18593
Reputation: 21
See Example 4 from the following command
get-help remove-item -Examples
"Because the Recurse parameter in this cmdlet is faulty..."
would be my guess.
Upvotes: 2
Reputation:
I had the same issue, i used the following to fix it:
dir E:\Music -File -Exclude *.mp3 -Recurse | Remove-Item
Upvotes: 6
Reputation: 126722
The command looks ok and should work. Do you get any output if you remove the pipe to foreach-object? Are you using PowerShell v3? Give this a try, do you get WhatIf messages?
dir E:\Music -File -Exclude *.mp3 -Recurse | del -WhatIf
Upvotes: 3