Create filepath string

I am trying to create a simple filepath. I want to add one variable in the middle of the filepath. To test I created a simple button which reads a value in, then I try to create the full filepath, and then write that filepath to a tag to confirm its coming out right. I get the following errors though.


You haven’t escaped your backslashes. Backslashes mark control codes in virtually every programming language on the planet. If you want a real backslash in a language’s quoted string, you need two of them.

(In python, triple quoted strings and the r'some\raw\string\with\backslashes' construct are exceptions.)

Your error message is especially cryptic because you put a backslash before a quote, making that quote part of the string instead of ending the string. Look at the color coding in your screenshot.

1 Like

Thanks! I still don’t get why I see other code that is written with only one backslash and it works. Anyways I put double slashes and got the following…


Because only certain escape sequences are valid. If the character following the backslash is a valid escape, it gets converted. If not, the backslash is left in place. Random crapshoot unless you know the escaping rules by heart.

In many places in python/jython/java, you can just use forward slashes as your directory separator and it will be translated to the OS format on your behalf. Try that.


Definitely what I would recommend.

1 Like