System.file File Path Only Works When User Selects File

I have a file in a known destination. I pre-define the path in a string and use system.file.readFileAsString() with the string path it says the file doesn’t exist.

If I use system.file.openFile(), and print the file path that it got to compare it omits one of the “\”

Why?

Does the “\” require an escape character?

yes. or try a r”yourpath”

3 Likes

r”path” worked

'r' is the "raw string modifier".

2. Lexical analysis — Python 2.7.18 documentation says,

Unless an 'r' or 'R' prefix is present, escape sequences in strings are interpreted according to rules similar to those used by Standard C.

1 Like

Even better fix is to just not use backslashes in your literal paths. Every Ignition API and Java API (and even most standard Jython lib APIs) will happily accept forward slashes, even on Windows.

5 Likes