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

del D:\myTempFolder\myTempFile.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:

\immediate\write18{del D:\textbackslash\myFolderName\textbackslash\myFileName}%

The file ``myTempFile.txt'' was not deleted. May I know where my mistake is? I think the problem here is escaping the backslash inside \immediate\write18 with the del command.

Thank you for any help.

  • by the way, i compiled using pdflatex with shell-escape. it has worked with my other \immediate\write18 lines, but not with the del command. Apr 10, 2020 at 16:21
  • 1
    I answered but I noticed this is a duplicate of my answer that is listed in the "Related" list at the right: tex.stackexchange.com/a/525430/1090 Apr 10, 2020 at 16:28

2 Answers 2


you can use

\@backslashchar as in

\immediate\write18{del D:\@backslashchar myFolderName\@backslashchar myFileName}%

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

\immediate\write18{del D:\string\myFolderName\string\myFileName}%
  • trying it now sir david... Apr 10, 2020 at 16:47
  • 1
    Not really: the OP wants expansion of the two commands.
    – egreg
    Apr 10, 2020 at 17:02
  • hi, the solution using \@backslashchar works. however, the solution using \string did not work for me. i dont know where my error is, if i missed a package or something. just the same, thank you sirs Apr 10, 2020 at 17:06
  • 1
    @beethovengg14 in both forms here I assumed the folder and file are literally myFolderName and myFileName if you meant them to be macros that expanded to the name they need slight adjustment Apr 10, 2020 at 21:34
  • 1
    @beethovengg14 if the file is d:\beethoven\thesis.tex you could use {del d:\string\beethoven\string\thesis.tex} but if you mean you have \def\MyFolder{beethoven}\def\myFile{thesis.tex} then you need {del d:\expandafter\string\myFolder\expandafter\string\myFile} Apr 11, 2020 at 10:10

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


and then something like

\dosystem{del D:\\myFolderName\\myFileName}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .