Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 need help on finding a tool to delete certain files with a specific file types from a directory on Windows.

Lets say I have a folder with 500 files, 150 files with extension .pdf, and 350 with .exe. I want a tool to delete .exe files automatically whenever they appear inside the folder.

share|improve this question
up vote 1 down vote accepted

If you want to automate this, you can use the Windows task scheduler.

Create a new task, and for the action, use

cmd.exe /c "del c:\folder\*.exe"

You can schedule this to run as frequently as you like. If you need to do this immediately as an .exe gets saved, then you'll want to enable auditing on the folder, and trigger the scheduled task on an audit event. I'll edit this and add it if this is important as it is quite involved.

share|improve this answer
Can we reverse this action to keep only .PDF & .txt files and delete every other file formats within the folder? This would be perfect. – Johan Larsson May 30 '12 at 22:57

You should be able to do this with a simple DOS command. The command would be something like this.

DEL /S /Q c:\MyFolder\*.exe

This will delete all files that have the .exe extension from the folder C:\MyFolder, and all subdirectories. You can omit the /S part if you don't want to delete from sub-directories. If you want to automate this, you can set this up as a scheduled task and run it as often as necessary. I won't be immediate in deleting the files, but if you run it frequently enough it should solve your problem.

share|improve this answer
Thank you too. I can only mark one answer as a valid answer for my questions, and it got to be Pauls answer. – Johan Larsson May 30 '12 at 15:39
This answer is the better, once it has the subdir option. Thx! – Rafael Borja Mar 25 '14 at 17:49

You must log in to answer this question.

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