Delete Files and Folders Recursively Using Command Prompt

One of our readers recently asked a question with regards to deleting files and folders recursively using the command prompt.

I would like to delete all the folders and files in a folder. Like we have an option to delete all the files is "del *" but it will not work for deleting folders like "rmdir *"

The question is similar to a one asked to us earlier where a user wanted to know how to recursively delete certain file types from directories and sub directories using the command prompt.

However when it comes to deleting directories and subdirectories using the command prompt, the regular rmdirdoes not work with a wildcard.

In order to delete all files and folders recursively using the command prompt you will need to run the command;

rmdir /S directoryname

Replace directorynamewith the directory you want to delete.


Once you run the command you will be prompted whether you want to delete the files or not, if you do not want to see this prompt you can pass the /Q switch to the command, which will then run the command in non-verbose mode.

However you must note that files and folders deleted from the command prompt do not go to recycle bin, they are permanently deleted, so make sure that you really want to delete those files, however if you do delete those files accidentally you can use one of the   to recover deleted files.

Published by

Keith Dsouza

I am the editor-in-chief and owner of Techie Buzz. I love coding and have contributed to several open source projects in the past. You can know more about me and my projects by visiting my Personal Website.I am also a social networking enthusiast and can be found active on twitter, you can follow Keith on twitter @keithdsouza. You can click on my name to visit my Google+ profile.

  • In linux, the command to do this is rm -rf folder_name

  • gourab

    how will i delete a folder in command prompt having some data in it(means folder is not empty.)

    • @gourab – The command mentioned above will delete all the sub-directories and files in a directory

      Just use "rmdir /S directoryname" command

  • joshuaslocum

    rmdir is NOT recursive……

  • I’m looking for a batch file solution which will delete all the CONTENTS of a folder (files and folders, recursively), but NOT the folder itself. I’ve been searching for hours but can’t find anything. The clunky solution would seem to be to delete the folder itself then recreate it with mkdir, but the folder is shared, and when I recreate it like this, it isn’t shared anymore. Any ideas?

  • WIlbur

    This only deletes a folder in the current directory. The “/s” option includes the folder’s files, it does not recurse down the tree. I am hoping you’ll update this article to do the actually hard part of recursively removing ever folder under a root that matches the pattern.

  • WIlbur

    Ok, ok, here ya go:

    FOR /R %d IN (.svn) DO rmdir /s /q “%d”

    • Thank you WIlbur, i had a large project that wasn’t properly exported from SVN and your solution solved my problem

  • Jaze

    nice! id love to know more:)

  • i do this and it says my path is too long :( any ideas?