FreeBASIC file operations with CWstr

Started by Juergen Kuehlwein, January 26, 2019, 03:35:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Juergen Kuehlwein

I thought i would open a new thread for file operations, because the other one is getting quite lengthy...

José,

i remember you posting somewhere, you had classes for unicode file operations, but i cannot find them (other than "CFileSys.inc, CFileTime.inc and CFindFile.inc) in WinFBX. Running own tests in FreeBASIC, it seems i cannot have unicode file names, but i can read and write WSTRINGs to and from files. So the real shortcoming is at the "OPEN" statement, all others work with WSTRING - is this correct ?


JK

José Roca

> So the real shortcoming is at the "OPEN" statement, all others work with WSTRING - is this correct ?

None of the FB instrinsic procedures that deal with files accept unicode file names.

José Roca

> i remember you posting somewhere, you had classes for unicode file operations, but i cannot find them (other than "CFileSys.inc, CFileTime.inc and CFindFile.inc) in WinFBX.

There are many classes and procedures to work with files in unicode.
See: https://github.com/JoseRoca/WinFBX/tree/master/docs/File%20Management

Juergen Kuehlwein

Ok, i cannot have unicode file names, but i can have unicode file data - can you confirm that? In other words: once i have opened a file, i can read and write WSTRINGs from and to it, at least this is what a quick test seems to show.


dim s as string
dim w as wstring * 16

  s = "d:\asdf.txt"
  w = "asdf"


  open s for binary as #1
    put #1,, w
  close #1 

  w = ""

  open s for binary as #1
    get #1,, w
  close #1 

  s = ""
  s = w
 
  print s
  print len(s)
  sleep


JK

José Roca

#4
I haven't tried with binary files, but it works with files opened with OPEN using "utf16" encoding.

Juergen Kuehlwein

It´s not about file encoding alone, i can read and write WSTRINGs from and to an ASCII encoded file, so basically unicode strings work with files, but real unicode file names fail. If you change "s" in my previous code example from string to wstring, it will work with the same file name, but with Russian characters, it fails. So there must be some conversion from wstring to string under the hood for the "open" statement.

This means - and this is my point: it would only require to enable unicode file names in order to get FreeBASIC working with unicode and files in total . The rest of it can already do that, of course the usual adaptions for avoiding "**" with USTRINGs would be necessary for the various input and output methods.

Having a look at the runtime library this seems to be the case!

Jeff, i know you are busy with other things, but can you confirm that?


JK   

Juergen Kuehlwein

In the meantime i have a very first version, which can open files with real unicode names (russian characters) using the "OPEN" statement. Making all file functions work with USTRING will be a whole lot of work, but at least i know now, that it is possible the way i thought.


JK

Juergen Kuehlwein

I´m making substantial progress here, i have converted almost all FB statements using filenames or paths to work with real unicode names. Currently i support: open, filecopy, fileattr, filelen, filedatetime, filexists, kill, name, command, exec, chain, run, dir, curdir, mkdir, chdir, rmdir and exepath.

There are still problems with: shell, environ, setenviron. Dylibload is yet to come.

Did i miss statements?


JK