Recursively Delete Selected Files or Folders In Windows

I was looking around for a way to recursively delete files and folders of a specific name in Windows. For example, imagine having “/folderA/folderB/file1.doc” and “/folderA/folderC/file1.doc”, and I wanted to remove all instances of file1.doc. Now imagine this file1.doc being presented in hundreds of folders. Deleting each file manually would drive anyone crazy.

I know Unix has a more powerful commandline interface, so operations like this should be a snap, but I was certain Windows had a similar functionality too. So I went about searching for a simple solution to do so. I was so intent on finding a simple batch file or DOS command that would do the recursive delete that I didn’t think of anything else until it suddenly slammed into me like a bullet train.

I could just use the search function in Windows! Yes that’s right — the normal Windows search is already a powerful enough function that accepts wildcards and does recursive searching. So I went to Windows search, specified my folder, and put in my filename. Sure enough, all the hundred or more instances of that file popped up almost instantly. From there it was just a matter of selecting all of them and deleting them. Everything took less than 10 seconds!

​Read More

Recursively Delete Files and Retain Folders in Windows

I was trying to delete all files in the current directory and all subdirectories, while keeping the directory structure intact. I found that I could use the following DOS command to recursively delete files, and NOT touch the directories:

ending in .doc

del /s *.doc

Do note though, that ALL files with the extension doc will be deleted. You can change .doc to something else, .mp3 .pdf .wav .am .rm .txt, it’s all up to you. If you require confirmation before deleting, you can have the del command prompt for confirmation before deleting each file by modifying the command slightly:

del /s /p *.doc

​Read More