Solved delete folder(s) with condition

August 24, 2013 at 00:25:39
Specs: Windows XP
In Mypath, I go other files, folders. Also, sometimes, I got only one "MyFolder_X" or I got more than one , "MyFolder_X", "MyFolder_X", ""MyFolder_X",.. X is a unique number.
In my script I try to check if there is only one folder that starts with "MyFolder_" then exit.
In my script I try to check if there is more than one folder that starts with "MyFolder_" then delete the the ones older than 5 days.

See More: delete folder(s) with condition

Report •

#1
August 24, 2013 at 02:54:58
"Date math" in batch is pretty much hopless.

Maybe someone will offer a VBS.

=====================
M2 Golden-Triangle


Report •

#2
August 24, 2013 at 16:16:42
So the real question is do you need to just delete any files by that name older than five days? Or will there be occasions where you will have nothing that's newer than five days ago?

::mike


Report •

#3
August 24, 2013 at 20:04:28
✔ Best Answer
M2 is correct, batch datemath pretty much sucks. Here's a vbscript workaraound:
'--------------- begin vbscript dcf.vbs
wscript.echo datediff("d", wscript.arguments(0), date)
'---------------- end vbscript

to use (for example):
for %%a in (myfolder_*) do (
for /f %%b in ('cscript dcf.vbs %%~ta') do echo %%b
)

My test seemed awfully slow however.


Report •

Related Solutions

#4
August 26, 2013 at 10:58:23
I think FORFILES was in WinXP. Look that command up.

How To Ask Questions The Smart Way


Report •

Ask Question