Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

With PowerShell, what is the most concise way to delete multiple explicitly named files?

E.g. on *ix it would be:

rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif

I'm currently using:

echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm

But I consider it suboptimal, so I would like to see alternatives.

share|improve this question
add comment

2 Answers 2

up vote 9 down vote accepted

You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.

rm .\subDir\a.png, .\anotherDir\b.jpg, .\thirdDir\c.gif

Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft TechNet.

share|improve this answer
add comment

This is what I ended up using:

echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm

This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.