IF EXIST *.%ext% ( rem Check if there are any in the current folder :)įOR /D /R %%G IN ("*") DO ( rem Iterate through all subfolders OFFĮCHO Enter the file extension you want to delete. The script will look in the folder it is in and all subfolders for any file with that extension and delete it. I wrote a batch script a while ago that allows you to pick a file extension to delete. See this answer on SU for more detailed information. For example, *.dll will match project.dll and project.dllold, which can be surprising.
The wildcard method will try to match all file names, in their 8.3 format, and their "long name" format. The lesson here is not to run such command directly at the root of a drive (or in any other location that might be dangerous, such as %windir%) if you can avoid it. All of your applications stop working, your computer becomes useless, and at the next reboot you are teleported in the fourth dimension where you will be stuck for eternity. Then you end up removing all dll files form your C:\ drive. REM This short script will only remove dlls from my project. However, if you are working on some project, and want to delete all your dll files in myProject\dll, and run the following batch file: off This is utterly annoying, but your computer will still be able to run. In the scenario where you delete jpg files using the second command, some applications might stop working, and you'll end up losing all your family pictures. The first command is executed from the current location, whereas the second is executed on the whole drive.
There's a huge difference between running del /S *.jpg and del /S C:\*.jpg. You can use wildcards with the del command, and /S to do it recursively.ĭel /S *.jpg asked why a downvoted answer ( del /s c:\*.blaawbg) was any different than my answer.