Forum > General

unicode(?) filename problems

(1/2) > >>

jmmx:
hi all  :)

i apologise in advance if my problem is a trivial one and i just missed the obvious here
but after reading all the relevant links and forum posts (i hope :) ) i still cant manage to load a text file with strange names.
i have a text file with hebrew or arabic name containing simple ansi text.
in this case its called טוטו
i do the following: (as described in http://www.lazarus.freepascal.org/index.php/topic,9690.0.html)

--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
  var
  LoadedFile:TMemoryStream;
begin
  if OpenDialog1.Execute then
begin
    ShowMessage (OpenDialog1.FileName);
    ShowMessage (UTF8ToSys(OpenDialog1.FileName));
    if FileExistsUTF8(OpenDialog1.FileName) then ShowMessage('yes!')
    else ShowMessage('no!');
    LoadedFile := TMemoryStream.Create;
    LoadedFile.LoadFromFile(UTF8ToSys(OpenDialog1.FileName));
end;
end;
--- End code ---


the output from showmessage is:
1) c:\טוטו
2) c:\????
3) yes!

immediately after the last showmessage i get
--- Code: ---Unable to open file "c:\????".
--- End code ---

what am i missing here?

im running windows xp pro, 32 bit, english.
tested with both stable lazarus and various snapshots.

Zoran:
There are many different one-byte encodings, UTF8ToSys and SysToUTF8 functions assumes the one defined for your current system. Try to identify the exact encoding, add LConvEncoding unit to uses list and see there the appropriate function for your encoding.

There you will see among others:

--- Code: ---...
function CP1255ToUTF8(const s: string): string; // hebrew
function CP1256ToUTF8(const s: string): string; // arabic
...
function UTF8ToCP1255(const s: string): string; // hebrew
function UTF8ToCP1256(const s: string): string; // arabic
...

--- End code ---

and other functions for other encodings... Try these.

theo:
Afaik this doesn't work yet on windows.
The FPC RTL is not ready for Unicode.
http://mantis.freepascal.org/view.php?id=15795

jmmx:
nop, still not working. tried a few things with LConvEncoding but to no avail.

ShowMessage (GuessEncoding(OpenDialog1.FileName)); -> utf8
ShowMessage (GetDefaultTextEncoding()); -> CP1252

is there really no solution to this?
not even a workaround?
i find it hard to believe no one here was confronted with reading silly named files in windows before...
it seems silly to me that i can "see" files on the system but not open them!

any suggestion will be appreciated... i really dont want to go back to delphi right now or migrate my project to another language :'(

ivan17:

--- Quote from: jmmx on November 17, 2010, 01:27:06 pm ---... or migrate my project to another language :'(

--- End quote ---
write twenty "hello world"s as a punishment for such a blasphemy!

seriously, is a trivial thing like that (rtl not supporting unicode filenames on windows) gonna stop cool and handsome programmers like you and me?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var sr: TSearchRec;      s: string;begin  if not OpenDialog1.Execute then Exit;  Button1.Caption := OpenDialog1.FileName;  FindFirstUTF8(OpenDialog1.FileName, faAnyFile, sr);  s := ExtractFilePath(OpenDialog1.FileName) + StrPas(sr.FindData.cAlternateFileName);;  FindCloseUTF8(sr);  Memo1.Lines.LoadFromFile(s);end; 

Navigation

[0] Message Index

[#] Next page

Go to full version