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
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
-
This is not limited to just the command prompt, it will work in powershell as well.– KeltariCommented Jul 26, 2020 at 2:15
Try this from powershell:
Get-ChildItem "Filepath" -Recurse |
Where-Object {$_.PSIsContainer -eq $false} |
Remove-Item
From powershell (or pwsh) you can do:
Get-ChildItem -File -Recurse | Remove-Item
-
1