Page 1 of 1

"Unexpected Do"

Posted: 28 Oct 2011 15:11
by tiggyboo
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

Re: "Unexpected Do"

Posted: 28 Oct 2011 15:41
by aGerman
Try:

Code: Select all

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


Regards
aGerman

Re: "Unexpected Do"

Posted: 30 Oct 2011 12:05
by trebor68
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.