Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete files or folder recursively on Windows CMD

People also ask

How do I delete a recursive folder in Windows?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How delete all files and folders using CMD?

The del command displays the following prompt: Are you sure (Y/N)? To delete all of the files in the current directory, press Y and then press ENTER. To cancel the deletion, press N and then press ENTER.

Can I delete a folder using CMD?

To delete folders in Windows 10 with CMD you have to use the rmdir command. This command will remove all folders including the subfolders and files in them.


The other answers didn't work for me, but this did:

del /s /q *.svn
rmdir /s /q *.svn

/q disables Yes/No prompting

/s means delete the file(s) from all subdirectories.


Please execute the following steps:

  1. Open the command prompt
  2. Change directory to the required path
  3. Give the following command

    del /S *.svn
    

You can use this in the bat script:

rd /s /q "c:\folder a"

Now, just change c:\folder a to your folder's location. Quotation is only needed when your folder name contains spaces.


RMDIR path_to_folder /S

ex. RMDIR "C:\tmp" /S

Note that you'll be prompted if you're really going to delete the "C:\tmp" folder. Combining it with /Q switch will remove the folder silently (ex. RMDIR "C:\tmp" /S /Q)


For file deletion, I wrote following simple batch file which deleted all .pdf's recursively:

del /s /q "\\ad1pfrtg001\AppDev\ResultLogs\*.pdf"
del /s /q "\\ad1pfrtg001\Project\AppData\*.pdf"

Even for the local directory we can use it as:

del /s /q "C:\Project\*.pdf"

The same can be applied for directory deletion where we just need to change del with rmdir.


If you want to delete a specific extension recursively, use this:

For /R "C:\Users\Desktop\saleh" %G IN (*.ppt) do del "%G"

You could also do:

del /s /p *.{your extension here}

The /p will prompt you for each found file, if you're nervous about deleting something you shouldn't.