W2K batch to recursively delete all folders with given name

  • Thread starter Thread starter Par_DD.RemoveThisToMailMe.
  • Start date Start date
P

Par_DD.RemoveThisToMailMe.

I've been trying to set up some batch files and I've gotten most of
them done with the help of google and many of the online resources.

One last batch that has me stumped is this.

I have a specific folder, C:\Pk\content

That folder may be empty, or it may contain many nested subdirectories.

I want to delete all occurances of folders named "html" and any files
that are in them under that \content directory.

The "html" folders will not be in the C:\Pk\content folder, but will be
nested several layers down (not more than 4).

I can get the right syntax to delete a folder named html, but I can't
get the syntax to do the recursion.

Any help greatly appreciated!
 
I've been trying to set up some batch files and I've gotten most of
them done with the help of google and many of the online resources.

One last batch that has me stumped is this.

I have a specific folder, C:\Pk\content

That folder may be empty, or it may contain many nested subdirectories.

I want to delete all occurances of folders named "html" and any files
that are in them under that \content directory.

The "html" folders will not be in the C:\Pk\content folder, but will be
nested several layers down (not more than 4).

I can get the right syntax to delete a folder named html, but I can't
get the syntax to do the recursion.

Any help greatly appreciated!

Hi Par.DD ?

@echo off&setlocal
pushd c:\PK\content
for /f "delims=" %%a in ('dir /B/S/AD html') do echo del %%a\?* /A-D
popd

If output looks okay remove the echo in front of del

HTH
Matthias
 
That got me most of the way there! That batch file cleaned out the html
folders, but the empty "html" folders stayed behind.

I was able to figure out that I wanted this instead: (posted for
completeness and to help others looking for the same file)

@echo off&setlocal
pushd c:\PK\content
for /f "delims=" %%a in ('dir /B/S/AD html') do rd /s /q "%%a"
popd

Now it deletes all the folders named html and their contents in the
specified directory.

Thanks again!
 
That got me most of the way there! That batch file cleaned out the html
folders, but the empty "html" folders stayed behind.
I wasn't shure the html folders were "leaves". The mentioned nesting
could have meant there are other folder inside the html ones.
I was able to figure out that I wanted this instead: (posted for
completeness and to help others looking for the same file)
I'm glad you could improve my suggestion by yourself.
 
Back
Top