Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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 at 17:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.