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 a batch file to traverse a directory structure that looks like this

C:\CruiseControl\ProjectArtifacts\ProjectName1\Logs C:\CruiseControl\ProjectArtifacts\ProjectName1\Src C:\CruiseControl\ProjectArtifacts\ProjectName1\Data C:\CruiseControl\ProjectArtifacts\ProjectName2\Logs C:\CruiseControl\ProjectArtifacts\ProjectName2\Src C:\CruiseControl\ProjectArtifacts\ProjectName2\Data C:\CruiseControl\ProjectArtifacts\ProjectName3\Logs C:\CruiseControl\ProjectArtifacts\ProjectName3\Src C:\CruiseControl\ProjectArtifacts\ProjectName3\Data

And so on...

The project name is always unique and there can be up to 100 variations on the ProjectName folder.

I want to delete the Src folder and all files/folders contained within it for each project. The Logs and Data folders should NOT BE deleted in this process. How can I go about doing this?

let me know if you need more info.

share|improve this question
up vote 1 down vote accepted

No batch file needed:

for /d %P in ("c:\CruiseControl\ProjectArtifacts\*") do @rd /s /q "%P\src" 2>nul

If you want a batch file, then change all %P to %%P

share|improve this answer
What if {Logs, Src, Data} aren't the only 3 directories? – Kruug Aug 21 '13 at 21:11
@Kruug - There could be any number of arbitrarily complex folders under each project, but the code above will only delete the ..\src folders (and all files and folders under it) from each project. The code does assume that all projects are at the same level of the directory tree, as was implied by the OP. – dbenham Aug 21 '13 at 22:13
I was way overcomplicating things :) thanks for the help! – Richie086 Aug 21 '13 at 23:38

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.