Solved BAT file to cleanup a folder if a certain file doesnt exist

June 3, 2012 at 18:50:04
Specs: Windows 7
Hi,

Im mucking around with a BAT file to cleanup folders recursively that dont meet a certain critera but have had no luck so far.

Heres the basic run down of what I need to do...

for each folder if not exist *.wtv delete *.xml *.jpg

So basically this would run through the "Recorded TV" folder, look in each folder and see if a file is in there with the extension WTV and if not then delete *.XML and *.JPG

seems fairly easy but I cant seem to get the FOR loops to work at all.

Thanks for any input or solutions at all.

bye


See More: BAT file to cleanup a folder if a certain file doesnt exist

Report •

#1
June 3, 2012 at 19:33:14
✔ Best Answer
:: ===== script starts here ===============
::
:: digi.bat Mon 04-06-2012 9:13:29.50
@echo off & setLocal enableDELAYedeXpansioN

pushd c:\files
for /f "tokens=* delims= " %%a in ('dir/b/s/ad') do (
pushd "%%a"
if not exist *.wtv echo del *.xml *.jpg
popd
)

goto :eof

::====== script ends here =================


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
June 4, 2012 at 20:40:41
Thanks M2 - you rock!

That worked perfectly. Have an awesome day


Report •
Related Solutions


Ask Question