How to write and read file paths to a binary file using Julia

Viewed 59

I am trying to establish my own file format and I am using binary as a base for it. I have to write many things of many different data types to this file but I seem to be having trouble with reading file paths back from the binary file, specifically, the "\" character seems to be causing me some issues. I know it is an escape character but it is behaving in a way I would not expect.

The following is what was written into the file...

"C:This\\is\\also\\a\\test;"

and I use this to read it back out (Note: I am using ';' as a delimiter as I can write an arbitrary number of paths each of arbitrary length to this file)

 reading = true
 while reading
      readbytes!(s,chartemp,1)
       
      recentlyread = Char(chartemp[1])
      @printf("char: %s\n",recentlyread)
      if recentlyread == ';'
           reading = false
           break
      end
      mat_folder = string(mat_folder,recentlyread)
 end

and what gets read back out is this...

"String[][\"C:This\\\\is\\\\also\\\\a\\\\test\"]"

I'm not sure if I am doing this the best way or where all these extra "\" are coming from. Any help you can provide would be greatly appreciated.

0 Answers
Related