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

In my C directory 3 folders are there named as DIR1 DIR2 DIR3 each folder contains folder Z. I want find all the Z folders. And I want to delete them. Is it possible? I dont no anything about windows.

I tried this command it's only listing, but how to delete.

dir c:\Z /s /d

enter image description here

share|improve this question
up vote 3 down vote accepted

This will remove all Z subdirectories keeping DIR1 DIR2 and DIR3:

for /D %d in (C:\DIR\*) do rmdir /S /Q %d\Z

See also:

for /?

rmdir /?
share|improve this answer
The above solution is working fine for me, now just imagine if there is a space in between "DI R" at that time what modification are needed in above command to avoid a space? – max Jan 13 '13 at 5:54
Enclose the paths in quotes: for /D %d in ("C:\DIR\*") do rmdir /S /Q "%d\Z" – utapyngo Jan 13 '13 at 6:08
Now the folder structure is changed, structure is like this "A S"->A->B-C->20130113-Z Here "A S" is the main folder, and I want to delete Z. – max Jan 13 '13 at 6:12
for /R "C:\A S" /D %d in (*) do @if "%~nd" == "Z" echo "%d" (replace echo with rmdir /S /Q) after testing. – utapyngo Jan 13 '13 at 6:21
Thanks a lot it's working :-) – max Jan 13 '13 at 6:23

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.