Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to delete all files (but not directories) in D:\MyTemp folder, I've tried:

Remove-Item "D:\MyTemp"
Remove-Item "D:\MyTemp\*"

However, when I check, all the files are still there.
What am I missing?

share|improve this question
up vote 7 down vote accepted

Try this:

Get-ChildItem *.* -recurse | Where { ! $_.PSIsContainer }

Found it here:

To delete all files in the specified directory only (ignoring sub-dirs):

Remove-Item "D:\MyTemp\*.*" | Where { ! $_.PSIsContainer }
share|improve this answer
This only lists file in the current directory – SteB Nov 2 '12 at 12:15
My bad, wasn't sure if you wanted to do recurse. I'll edit the original. You can just add -recurse to the Get-ChildItem command – bourne Nov 2 '12 at 12:17
This works (only delete files from specified directory, ignoring sub-dirs): Remove-Item "D:\MyTemp\*.*" | Where { ! $_.PSIsContainer } – SteB Nov 2 '12 at 12:22
That's great. Glad you got it working. – bourne Nov 2 '12 at 12:42
Sorry btw SteB, I just noticed I forgot to include the Remove-Item. It's going to be a long day wow! – bourne Nov 2 '12 at 12:50

The accepted answer didn't work for me, instead I needed:

Get-Childitem -File -Recurse | Foreach-Object {Remove-Item $_.FullName}
share|improve this answer

Your Answer


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.