Solved For loop with argument to delete folders

October 6, 2015 at 14:37:34
Specs: Windows 7
I need a "For" loop to recursively delete folders based on an argument with a wild card. I need to delete all subfolders that begin with "04" in a tree "Data" that contains Months in the first level, and Days in the second. The "040800" folder would be in "Jan" and "Feb", but not in the first folder, "Data".

The structure is:

See More: For loop with argument to delete folders

Report •

October 6, 2015 at 14:47:43
I'd like to pass the argument "04" to a batch file.

Report •

October 6, 2015 at 21:29:36
:: butt-load of safeties on, but you know how to remove them...
@echo off
set deltarg=%1
if not defined deltarg (
echo USAGE: %0 element
goto :eof
pushd data
for %%a in (jan feb mar apr may jun jul aug sep oct nov dec) do (
pushd %%a
:: safety-display - remove when confident...
for /d %%b in (%deltarg%*) do echo rd /s /q %cd%\%%a\%%b
:: safety is ON, remove REM to enable destruction
REM for /d %%b in (%deltarg%*) do echo rd /s /q %%b

message edited by nbrane

Report •

October 6, 2015 at 21:29:37
✔ Best Answer
::====== script starts here ===============
:: jpaul.bat 2015-10-07 10:51:31.40
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

:: here's where you push to your data directory
pushd d:\

for /f "tokens=* delims= " %%a in ('dir/b/s/ad 888*') do (
del/q "%%a"
::====== script ends here =================


M2 Get custom script or take private lessons

Report •

Related Solutions

Ask Question