Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want to search and delete *.mp4 *.mpeg, *.mkv, *.flv, *.avi (all video files) from all drives (C,D,E,F) or anywhere in my computer in any directory or subdirectory, using BATCH File. My operatin system is windows XP.

share|improve this question
Hmm, I threw together a batch-file and it worked at one point, but when I cleaned it up a bit, it stopped working. I undid the changes I made after it was working and reverted it to the point where it had previously worked, but it still wouldn’t work. ಠ_ఠ Stupid computers with their intermittent, indeterministic behaviors. ¬_¬ I’ll try to fix it… – Synetech Oct 6 '13 at 14:53

for %%drive in (C D E F) do (
    for /R %drive:\ %%f in (*.mp4 *.mpeg *.mkv *.flv *.avi) do (
        @echo del "%f"


I have no means to test this right now. Just run it and see, if it does everything right. Afterwards remove the @echo and run it again.

share|improve this answer
Hi David, Thanks for your reply, I try to use this command using batch file but nothing is happend. The batch file runed but not showing any result. I have MS Windows XP Prof.2002 SP3 OS. – Vinayak Shinde Oct 4 '13 at 9:31
Could you reproduce the error message, please? I wrote my last non-trivial batch script years ago and most probably included some sort of invalid syntax. – David Foerster Oct 4 '13 at 9:51
Hi David, After running the batch file, its not showing any kind of error. Its only open and close in fraction of second. So i am also unable to understand the error. – Vinayak Shinde Oct 5 '13 at 5:19
You need to open a command prompt window (Windows+R, enter cmd.exe and press Return or click OK) and execute the batch file or command sequence from there. It will remain open afterwards. – David Foerster Oct 5 '13 at 8:37
"%drive was unexpected at this time" this is the error and after this the command execute without error, but no files remove. – Vinayak Shinde Oct 6 '13 at 4:08

First of all, it could be quite dangerous to blindly delete files with a batch file because it would wipe out anything and everything. And while this is seemingly your goal, you have to be aware that it would also destroy files that are part of the operating system (Windows comes with a few videos here and there), as well as any programs and games that have video files. If your goal is to free up space, then there are better ways to do that (besides, not all videos are large).

Anyway, after my initial version magically stopped working for no apparent reason (yes, I tried to account for everything), I ended up using a work-around. The only draw-back to using pushd is that if you abort the batch-file, you’ll end up in whatever drive it was in when you pressed Ctrl+Break.

Instead of just blindly deleting everything, I made it so that it builds a secondary batch-file (delmovie.bat) which you can scan through to make sure there isn’t anything you want to keep. Then you can just run the generated batch-file to delete them. It takes a few extra seconds but is much safer.

@echo off
echo @echo off > delmovie.bat
for %%i in (C:\Users C:\Videos D:\ E:\ F:\) do (
  pushd %%i
  for /r %%j in (*.mp4 *.mpeg *.mkv *.flv *.avi) do (
    echo del "%%j" >> %~dp0delmovie.bat

This version excludes system directories with a white-list, not a black-list, so instead of excluding directories you want to ignore, it adds the ones you want to scan (doing the other way around would be a little more complex and I can provide a script to do that if you need). I added c:\videos as an example of how you can add your own directories if needed (it doesn’t hurt anything to leave c:'videos in there if you don’t have such a directory).

share|improve this answer
Thanks a Lot. It will work for me. Is any way, to not delete any video files related to system files by changing anything in this code. Like make read only for the C:\Program Files & C:\Windows folder. Like this. – Vinayak Shinde Oct 10 '13 at 9:49

Your Answer


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.