Powershell delete files only from directory

powershell

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?

Best Answer

Try this:

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

Found it here: https://superuser.com/questions/150748/have-powershell-get-childitem-return-files-only

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

Remove-Item "D:\MyTemp\*.*" | Where { ! $_.PSIsContainer }