The parens around s in file(s) also need to be escaped to prevent other problems:
for /F "tokens=1,2 delims= " %%i in ('dir %%X\%SRC5%\*.*') do if "%%j"=="File^(s^)"
Main Topics
Browse All TopicsI've almost got my cleanup bat working. I'm getting a ") was unexpected at this time" at the "for /F "tokens=1,2 delims= " %%i in ('dir %%X\%SRC5%\*.*') do if (%%j)==(File(s)) set _Count=%%i" line. Ideas? Thanks.
@echo off
SET SRC1=C:\Profiles
SET SRC5=Cookies
SET SRC4=Webex
SET SRC3=Application Data\Microsoft\HTML Help
REM CLEANUP COOKIES FOLDER
REM FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.txt") DO ECHO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO (
REM DELETE COOKIES IF > 200 THEN ONLY > 90 DAYS OLD
for /F "tokens=1,2 delims= " %%i in ('dir %%X\%SRC5%\*.*') do if (%%j)==(File(s)) set _Count=%%i
REM ECHO _Count %_Count%
REM ECHO i %%i
if %_Count% GE 200 FORFILES -p%%X\%SRC5% -m*.txt -d-90 -c"CMD /C echo del %%X\%SRC5%\@FILE"
REM CLEANUP WEBEX
ECHO DEL /F /S /Q "%%X\*.tmp"
ECHO DEL /F /S /Q "%%X\*.dll"
ECHO DEL /F /S /Q "%%X\*.exe"
FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO ECHO RMDIR /S /Q "%%X\%SRC4%" *********
REM CLEANUP HTML Help
ECHO DEL /F /S /Q "%%X\Application Data\Microsoft\HTML Help\*.chw"
REM CLEANUP OLD SCREWDRIVERS LEFT BEHIND FILE
ECHO DEL /F /S /Q "%%X\pmp.txt"
)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I believe that is an incorrect statement. Trying to escape parens will result in no match. Try it out:
@echo off
for /F "tokens=1,2 delims= " %%i in ('dir *.*') do if "%%j"=="File^(s^)" echo %%i
This will result in nothing.
@echo off
for /F "tokens=1,2 delims= " %%i in ('dir *.*') do if "%%j"=="File(s)" echo %%i
This will result in the number of files are required by the processing.
Business Accounts
Answer for Membership
by: SteveGTRPosted on 2005-11-18 at 22:31:30ID: 15325132
Use this instead:
for /F "tokens=1,2 delims= " %%i in ('dir %%X\%SRC5%\*.*') do if "%%j"=="File(s)" set _Count=%%i
In and by itself your version should work, but when you nest it in a block the interpret gets confused by the parenthesis.
I just ran into this problem with a if block something like this:
@echo off
if 1==1 (
echo (hello)there
)
This gets a syntax error stating:
there was unexpected at this time.
A work around for my case was to use the go old not condition and just around the code instead of using the block:
if not 1==1 goto SKIPIT
echo (hello)there
:SKIPIT
Good Luck,
Steve