julia> println("@echo off
Del %cd%\\*.png
echo delete complete!
pause
")
@echo off
Del %cd%\*.png
echo delete complete!
pause
julia> println("@echo off
Del %cd%\\\\*.png
echo delete complete!
pause
")
@echo off
Del %cd%\\*.png
echo delete complete!
pause
Backslash (\) is the ‘escape character’ used to skip control sequences encountered in strings. In this case, you’re escaping another backslash, so you can either use four consecutive backslashes (\\\\) as mentioned above, or a raw string that ignores control sequences and escapes (raw"%cd%\\.png").
If you just want the string to be written out directly to the file, and don’t need special escape sequences (\n, \t, etc.) or Julia variables inside the string, then you can just add raw at the beginning of the string:
function delete_bat()
io = open("delete_png.bat","w")
write(io, raw"@echo off
Del %cd%\\*.png
echo delete complete!
pause
")
close(io)
end
delete_bat()
Within raw strings, Julia does no special interpretation; what you see is what you get.
Roughly it goes like this. A string is something that starts and ends with quotation marks. Now suppose you want to have a string which contains quotation marks, say """", would that be one string containing two quotation marks or two empty strings? There are some possible ways to resolve this but a common approach is to introduce an “escape” character, commonly backslash, meaning that a quotation mark following the escape character is a quotation mark within the string and not a string delimiter. Thus a string containing two quotation marks is encoded as "\"\"". But how would you now write a string containing a backslash? If you try "\" the second quotation mark is an escaped quotation mark and not the end of the string. The solution is to let the escape character escape itself, so "\\" means a string containing a single backslash. Then when we have an escape convention it’s natural to introduce more escape codes for useful things, like "\n" meaning a newline.