Recursively delete files in Windows

Posted October 11, 2003 by Quinn McHenry in Windows

The del command allows recursive removal of specified files.

To delete all files ending in .tmp in the current directory and all subdirectories, use:

del /s *.tmp

Warning: Be certain you know exactly what you are doing before using the command. To be more careful, you can specify that the del command will prompt for confirmation before deleting each file:

del /s /p *.tmp


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

  • Rajesh

    May I know how to the “folders” instead of files recursively?
    (Assume the folders aren’t empty.)

  • Rajesh

    ** May I know how to DELETE the “folders” instead of files recursively?
    (Assume the folders aren’t empty.)

  • dhanu

    thank you very much

  • Anonymous

    Thanks for this. It works in seconds.

  • Roshan


  • Marcus


  • Photographer of raw and JPG

    I am a photographer and generate “raw” and JPG images. At a certain point in my workflow, I need to delete all the JPG images before proceeding. That’s easy enough; in Windows Explorer, one can sort by type, then delete all the JPGs, or one could open up a command prompt in the directory and “erase *.jpg”. But there’s a complication; in some modes of the camera, no raw file is generated. In those cases, I just have one .jpg that I want to keep. Here is an example:


    I want to process this directory and end up with one file of each filename, as follows:


    The pseudocode would go something like this:

    Sort files by filename fname

    IF fname.jpg and fname.cr2 both exist THEN delete fname.jpg

    How can I easily do this? Thanks!

  • `rmdir /q /f dir1`
    alternatively, you can use the ‘robocopy’ command included in windows 7. Make a new empty directory, and then copy the empty directory to the directory you want to erase.
    `robocopy new-blank-dir delete-dir /purge /mir`

  • Yoel Feuermann

    it still prompts for each file. how do I change this?