# Missing characters when creating .bat file in Julia

**URL:** https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252
**Category:** New to Julia
**Tags:** question
**Created:** [October 25, 2022, 3:28pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252 "2022-10-25T15:28:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Funkerfish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/funkerfish/32/37982_2.png) [@Funkerfish](https://discourse.julialang.org/u/Funkerfish)
#### Post date: [October 25, 2022, 3:28pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/1 "2022-10-25T15:28:56Z")

</div>

Hi everyone!

I have a problem with the file system.

I want to create a .bat file in order to delete all the .png files in the folder.

the .bat file should be:

```julia
@echo off
Del %cd%\\*.png
echo delete complete！
pause

```

while the julia create a .bat file with a missing character “/”

```julia
@echo off
Del %cd%\*.png  
echo delete complete!
pause

```

my code is,

```julia
function delete_bat()
io = open("delete_png.bat","w")
write(io,"@echo off
Del %cd%\\*.png
echo delete complete!
pause
")
close(io)
end
delete_bat()

```

Could you please help me?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 25, 2022, 3:57pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/2 "2022-10-25T15:57:10Z")

</div>

Backspaces need to be escaped:

```julia
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

```

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [October 25, 2022, 3:58pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/3 "2022-10-25T15:58:47Z")

</div>

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`").

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [October 25, 2022, 4:28pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/4 "2022-10-25T16:28:36Z")

</div>

Instead of a batch file, you could do it directly from Julia. This would have the advantage that it would also work on Linux or a Mac:

```julia
using Glob
function delete_files(;ext="png", directory=pwd())
    ndeleted = 0
    cd(directory) do
        files = glob("*." * ext)
        foreach(rm, files)
        ndeleted = length(files)
        println(ndeleted, " .", ext, " files deleted from ", directory)
    end
    return ndeleted
end

```

---

<div class="post-metadata">

### Author: ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)
#### Post date: [October 25, 2022, 5:56pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/5 "2022-10-25T17:56:15Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

### Author: ![Funkerfish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/funkerfish/32/37982_2.png) [@Funkerfish](https://discourse.julialang.org/u/Funkerfish)
#### Post date: [October 25, 2022, 8:26pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/6 "2022-10-25T20:26:47Z")

</div>

Really thank you guys! my problem solved.  
but why it would be `//` when `println("//")`? Is there anything special?

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [October 25, 2022, 8:45pm UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/7 "2022-10-25T20:45:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 26, 2022, 5:10am UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/8 "2022-10-26T05:10:10Z")

</div>

Because in Julia the escape character is `\` and not `/` 🙂

---

<div class="post-metadata">

### Author: ![Funkerfish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/funkerfish/32/37982_2.png) [@Funkerfish](https://discourse.julialang.org/u/Funkerfish)
#### Post date: [October 26, 2022, 5:18am UTC](https://discourse.julialang.org/t/missing-characters-when-creating-bat-file-in-julia/89252/9 "2022-10-26T05:18:03Z")

</div>

my mistake 😅… thanks
