TransWikia.com

escaping the backslash inside immediatewrite18 with del command

TeX - LaTeX Asked by beethovengg14 on July 9, 2021

I pasted the following line into the DOS PROMPT/DOS Command Line:

del D:myTempFoldermyTempFile.txt

It worked well — I was able to delete the file myTempFile.txt'' inside the foldermyTempFolder”. I did not use the forward slash since it has a different meaning (switches) when associated with the del command.

I was wondering if I can implement the preceding routine inside a LaTeX file, so i tried the following:

documentclass{article}%
newcommand*{myFolderName}{myTempFolder}
newcommand*{myFileName}{myTempFile.txt}
begin{document}
immediatewrite18{del D:textbackslashmyFolderNametextbackslashmyFileName}%
end{document}

The file “myTempFile.txt” was not deleted. May I know where my mistake is? I think the problem here is escaping the backslash inside immediatewrite18 with the del command.

Thank you for any help.

2 Answers

you can use

@backslashchar as in

makeatletter
immediatewrite18{del D:@backslashchar myFolderName@backslashchar myFileName}%
makeatother

or more simply avoid expanding the undefined tokens myFolderName by using string.

immediatewrite18{del D:stringmyFolderNamestringmyFileName}%

Correct answer by David Carlisle on July 9, 2021

I like the solution found here, in this case it will need to add this:

makeatletter
newcommanddosystem{%
  @ifstar{@tempswafalsedo@system}{@tempswatruedo@system}%
}
edef@hashmark{string#}edef@lbrace{string{}edef@rbrace{string}}
newcommanddo@system[1]{%
  begingroup
  let@backslashchar
  let%@percentchar
  let#@hashmark
  let{@lbrace
  let}@rbrace
  if@tempswaexpandafterimmediatefi
  write18{#1}%
  endgroup
}

and then something like

dosystem{del D:myFolderNamemyFileName}

Answered by alexis on July 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP