I need to delete all the folders in current directory that starts with say \"foo\" followed by date
for example we have
The magical for command in dos batch....
from the command line
for /f "tokens=*" %f in ('dir .\foo* /ad/b') do rd "%f" /s/q
from the batch file
for /f "tokens=*" %%f in ('dir .\foo* /ad/b') do rd "%%f" /s/q
/f runs the command in the '' in the brackets, and tokenises its. By saying tokens=* all the file/dir name goe into one variable %f
here is an example
C:\temp>md foo3
C:\temp>md foo2
C:\temp>md foo1
C:\temp>dir
Volume in drive C is TEST
Volume Serial Number is F47F-AAE1
Directory of C:\temp
18/06/2012 09:42 p.m. .
18/06/2012 09:42 p.m. ..
18/06/2012 09:42 p.m. foo1
18/06/2012 09:42 p.m. foo2
18/06/2012 09:42 p.m. foo3
0 File(s) 0 bytes
5 Dir(s) 131,009,933,312 bytes free
C:\temp>for /f "tokens=*" %f in ('dir .\foo* /ad/b') do rd "%f" /s/q
C:\temp>rd "foo1" /s/q
C:\temp>rd "foo2" /s/q
C:\temp>rd "foo3" /s/q
C:\temp>dir /ad
Volume in drive C is TEST
Volume Serial Number is F47F-AAE1
Directory of C:\temp
18/06/2012 09:42 p.m. .
18/06/2012 09:42 p.m. ..
0 File(s) 0 bytes
2 Dir(s) 131,009,933,312 bytes free
C:\temp>