Batch file help. %%i was unexpected at this time (also Pause is ignored)

Posted on 2007-07-30
Last Modified: 2007-11-27
I have the following batch file running fine at an other site sending me latest NTbackup Logs.

When trying to run it on this server (Server 2003 Standard Server SP1) it fails. Pls see below

@echo off
::Batch file - send out latest backuplog*.log file in current folder

rem Gathering all files in current folder with mask specified...
rem /A-D... no directories (or folders)
rem /OD... sort by date (oldest first)
rem /B... no heading information or summary rem /TW... last Writen file

dir backuplog*.log /A-D /OD /TW /B >tmp.txt

rem parse tmp.txt file to get last line...
rem last line is latest .log file...
rem so attach.txt will contain .log file we want...
for /F "tokens=*" %i in (tmp.txt) do echo %i >attach.txt      <-- this is where it fails with a %%i was unexpected at this time.

febootimail -smtp SERVER -subject "NTBackup Logs" -FROM -TO -ATTACH -USEFILE attach.txt

Also when I stick a pause line in the batch file during troubleshooting it ignores the pause.

I usually run the batch file from "C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data" folder

Any help appreciated

Question by:wilsonkjit
    LVL 142

    Accepted Solution

    please try this:

    for /F "tokens=*" %%i in (tmp.txt) do echo "%%i" >attach.txt

    Author Comment

    Thanks for your reply.
    Very Nearly.....
    it creates the attach.txt (contents of file "backuplog07.log")

    the only problem now is for the next febootimail line to work I need the backuplog07.log to not be enclosed by "" in attach.txt.

    Any ideas?
    Cheers for your help..


    Author Comment

    D'oh -
    Sorry last post was dumb, I just answered my own question.. take out the "" surrounding %%i
    Case closed its working
    Thanks sooo much


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now