"Unexpected Do"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tiggyboo
Posts: 5
Joined: 28 Oct 2011 15:06

"Unexpected Do"

#1 Post by tiggyboo » 28 Oct 2011 15:11

The following, from within a batch script:

echo for %%A in ("DM.txt") do if %%~zA equ 0 del DM.txt >> exec-ds.bat

Generates:

"do was unexpected at this time"

However if I run it manually, no error is generated and exec-ds.bat executes as expected. Any suggestions?

Thanks,
Al

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: "Unexpected Do"

#2 Post by aGerman » 28 Oct 2011 15:41

Try:

Code: Select all

>>"exec-ds.bat" echo for %%%%A in ("DM.txt") do if %%%%~zA equ 0 del "DM.txt"


Regards
aGerman

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: "Unexpected Do"

#3 Post by trebor68 » 30 Oct 2011 12:05

If you want the text after the command echo in the file.
echo text >> exec.bat

Please double the sign "%" to "%%"

Here the code for your batch file:

Code: Select all

echo for %%%%A in ("DM.txt") do if %%%%~zA equ 0 del DM.txt >> exec-ds.bat


In the file "exec-ds.bat" can you see:

Code: Select all

for %%A in ("DM.txt") do if %%~zA equ 0 del DM.txt


I think that is the solution.

Post Reply