Recursively delete files 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.

9 Responses to “Recursively delete files in Windows”

  1. January 13, 2009 at 10:09 pm, Rajesh said:

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

    Reply

  2. January 13, 2009 at 10:10 pm, Rajesh said:

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

    Reply

  3. February 10, 2009 at 5:52 am, dhanu said:

    thank you very much

    Reply

  4. February 25, 2010 at 10:19 am, Anonymous said:

    Thanks for this. It works in seconds.

    Reply

  5. May 03, 2011 at 2:20 pm, Roshan said:

    Thanks!

    Reply

  6. August 01, 2013 at 9:59 am, Marcus said:

    Cheers!

    Reply

  7. November 11, 2013 at 9:32 pm, Photographer of raw and JPG said:

    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:

    img1.cr2
    img1.jpg
    img2.cr2
    img2.jpg
    img3.jpg
    img4.cr2
    img4.jpg

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

    img1.cr2
    img2.cr2
    img3.jpg
    img4.cr2

    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!

    Reply

  8. December 01, 2013 at 5:36 am, felipe1982 said:

    `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`

    Reply

Leave a Reply