0
echo ((goto) 2>nul & cd "%~dp0\.." && rmdir /s /q "%~dp0") >> delete.bat

I'm using a batch file to create another separate batchfile by running this command. However, the line above doesn't appear at all in the "delete.bat" file. I'm sure it's an issue with the syntax, but I'm unable to see what the issue is exactly. Anyone got a clue?

servicecli
  • 95
  • 9
  • The double ampersand has to be escaped. – jwdonahue Mar 13 '18 at 22:17
  • I question why you need to do this. Why can't you write a script file and just call that with the appropriate parameters? If it's a clean-up script then write a data file for it to read. Lower complexity is always good. – jwdonahue Mar 13 '18 at 22:38
  • ...as well as the caret escaped ampersands, all percent characters require doubling up too! – Compo Mar 13 '18 at 22:41

1 Answers1

0
> echo test ^&^& test
test && test
> echo test && testing
test
'testing' is not recognized as an internal or external command,
operable program or batch file.

Cmd.exe is interpreting your echo line as two commands due to the &&. You need to escape them with the ^ hat to get them emitted into the script.

See Quoting and escaping.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43