I think you’re misunderstanding escape_string — it is not to help you type the literal string, but rather it is there to help you add backslashes to an existing string, primarily for printing.
So, when you type this path as a literal string, you still need the extra backslashes:
Note that it is displayed between "..." as you would type it, with the escaped backslashes, but these are not actually stored in the string, as you can see if you print it:
julia> println("This is the mypath string: ", mypath)
This is the mypath string: C:\Users\User\Dropbox\codes\JULIA\stock1\
You can also enter the same string using raw"..." if you want to avoid having to type so many backslashes, although you still to escape the final backslash:
As mentioned above, escape_string actually adds the backslash escapes into the string, which looks a bit weird if you display it because \\ is displayed escaped as \\\\:
The reason for escape_string is more apparent if you print it:
julia> println("This is the mypath string WITH ESCAPES: ", escape_string(mypath))
This is the mypath string WITH ESCAPES: C:\\Users\\User\\Dropbox\\codes\\JULIA\\stock1\\
Some form of escaping is used for literal strings in every programming language, because of the inevitable need to distinguish between language syntax and the contents of the string for things like string delimiters. xkcd:
Who is the “user” here? Are you typing the path, or are you reading it from some external source?
(The above won’t work because mypath = "..." is Julia code and needs to follow Julia syntax — you need to escape backslashes or use raw"...". I’m not sure you know what escaping actually means yet?)
In Julia string literals, the backslash has special meaning so that you can add non-printable characters (such as the newline) or, include the double quote.
julia> print("The sun came over the horizon.\nHe said: \"Beautiful!\"")
The sun came over the horizon.
He said: "Beautiful!"
This is why using slash in a string literal is complex. So, to actually include a slash in your output string, you have to double it.
Anyway, I’d avoid eval and Meta.parse – it’s exceptionally rare you’d ever need to use them. I’ve been using Julia for years in some complicated works and have found only a few cases where Meta.parse and eval were indicated.
If the external source is not Julia code (e.g. you are reading the filename using read or from a file-picker prompt), then the user won’t need extra backslashes. Escaping is only needed when strings are entered literally in Julia code.
…in Julia code. The point is that when you have a string "...." in Julia code (a string literal), this is only a representation of the actual contents of the string, and is not the same as the string itself as it is stored in memory. A backslash in the underlying string is represented in Julia code by a string literal with an escaped (backslashed) backslash (a double backslash).
In the same way, if you want a string with a quotation mark, you need to represent it in Julia code with an escaped backslash: "a quote \" in a string". This is, in some sense, the origin of escaping: if you didn’t mark (escape) the quotation mark in some special way, Julia couldn’t distinguish it from the end of the string. But then once you settle on \" as the way to escape a quote ", then you need a way to escape the backslash itself.
Again, this is not specific to Julia. Every programming language has some version of string escaping.