Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For the file example, I would like to delete all files matching .+?[a-f0-9]{4}.html (i.e. any html file ending in a four digit hexadecimal). So paged47c.html would be deleted, but page.html would remain.

For the folder example, I would like to delete all folders matching .+?[A-Z]+ (i.e. any folder containing a capital letter). So some-folderSE93_89ds/ would be deleted, but some-folder/ would remain.

I don't work much with the command line, but I could probably get an example involving "del" to work for me. Alternatively, is there a simple GUI program for Windows that would do this?

share|improve this question

I would say the easiest way, albeit not the direct route, is to do your specialized dir command (you can use /b and /s switched to make it just list the filename and to recurse directories) and redirect it to a file. Open it in notepad (or insert your favorite editor), search and replace to add "del " to the beginning of the lines, save it off as mydel.bat, and execute.

So an example would be:

dir /s /b *.html > mydel.bat
notepad mydel.bat
call mydel.bat

share|improve this answer
How would I delete all files not named "test.txt"? – Jay Sullivan Jan 26 '15 at 22:22

Use the following line in powershell:

Get-ChildItem -Recurse C:\| where { ! $_.PSIsContainer } | Where-Object {$_.Name -match ".+?[a-f0-9]{4}.html"}

Is for the file case, for the folder case use:

Get-ChildItem -Recurse C:\| Where-Object { $_.PSIsContainer }| Where-Object {$_.Name -match ".+?[A-Z]+"}

Store those both in variables, and then use Remove-Item

Warning: In my command, I am using the root C:\ as the source location. If you do want to pipe it's output to Remove-Item and you are running this as administrator, its a bad idea. At the very least do one of the following:

  1. Specifically exclude Windows
  2. Using the what-if flag
  3. Don't run as administrator (if the files that you are matching are not in a protected directory, it won't matter)
  4. Don't run use C:\ but rather from some safer place
share|improve this answer
This helped me, thanks. I'd recommend changing the C: to .--I just ran it not realizing you pointed it to C:--good thing you didn't put the Remove-Item in there :) – Jay Sullivan Jan 26 '15 at 22:31
@notfed, point well taken – soandos Jan 27 '15 at 0:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.