3

For a given folder, I need to delete all files (various extensions) in all subfolders but not the subfolders themselves because I need to preserve the folder structure. Is there a way to do that via command line or a batch file?

3 Answers 3

6

Run the Command Prompt and enter the following commands:

cd /D "your folder"
del /S /Q *.*

This will list all the files as they are being deleted. To not see this, change the second command to:

del /S /Q *.* >nul 
1
  • This is not limited to just the command prompt, it will work in powershell as well.
    – Keltari
    Commented Jul 26, 2020 at 2:15
1

Try this from powershell:

Get-ChildItem "Filepath" -Recurse | 
  Where-Object {$_.PSIsContainer -eq $false} |
     Remove-Item
0

From powershell (or pwsh) you can do:

Get-ChildItem -File -Recurse | Remove-Item
1
  • 1
    This exact command was suggested nearly 3 years ago
    – Ramhound
    Commented Jan 28, 2023 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .