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

I need to delete all sub-folders in a folder tree that match the pattern "images".
I can remove all files matching a pattern using

del /s myfolder\images*.*

but it doesn't work for directories.
I tried with rmdir too but without success

share|improve this question

migrated from Feb 4 '13 at 6:42

This question came from our site for professional and enthusiast programmers.

rmdir -r works in my OS - but you did tag as Windows... The -r flag means "recursively". To force deletion you add f, so rmdir -rf. VERY dangerous command... – Floris Feb 4 '13 at 4:29
up vote 3 down vote accepted

rmdir /s may be what you want to purge a sub-tree, and, as Floris said, this is very dangerous.  If I understand your question correctly, you want to be able to delete myfolder\a\b\c\holiday_images while leaving myfolder\a\b\c\holiday_videos intact.  This should do what you want:

for /d /r %i in (*image*) do @rmdir /s %i

This is native Windows functionality; no need to download or install anything.

share|improve this answer

rm -rf myfolder/images will delete without asking otherwise you can go -ri to confirm every deletion.

share|improve this answer
Ok i have "rm" from GnuWin32 package. However it won't delete the subfolder "myfolder\subfolder1\images". It only removes folders named "myfolder\images1", "myfolder\images2", etc (using asterisk: "rm -rf myfolder\images*") – Bear Bear Feb 4 '13 at 5:37
rm -rf myfolder/images/* will remove all files in images, but rm -rf myfolder/images should remove that folder and all of its contents – Jarealist Feb 4 '13 at 15:19

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.