Forum > General

TMemoryStreamUTF8 cannot LoadFromFile

<< < (3/9) > >>

martinrame:
I did an: ls /directory/file|hexdump -C to see the actual ascii codes of the filename and found the Ñ is replaced to the hex a5, then I did this:


--- 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";}};} ---lFile := AnsiReplaceStr(lFile, 'Ñ', chr($A5));                                        lPdfStream.LoadFromFile(lFile);
But still I can't open the file with LoadFromFile.

martinrame:
Traversing char by char, the string returned by the database I'm getting this:


--- 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";}};} ---P=80E=69=195=145A=65L=76O=79Z=90A=65 
Compared to the output of hexdump I get:


--- 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";}};} ---ls /mnt/Informes/202205/PE*19900.pdf|hexdump -C -s 36 -n 800000024  2f 50 45 a5 41 4c 4f 5a                           |/PE.ALOZ|0000002c 
The difference is the file name contains a5 (Ascii 165) in the place of the Ñ, while the string returned by the database contains ASCII 195 followed by 145.

It looks like the database is effectively using UTF8, while the file naming is ASCII. Is there a way to convert between those incodings?

martinrame:
I replaced that with:


--- 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";}};} ---lFile := StringReplace(lFile, #195#145, #165, [rfReplaceAll]);
But still getting the "Unable to open file...No such file or directory".

martinrame:
The funny thing is that FileExists returns true when I check both the UTF8 file name and the one whith replaced #195#145 with #165. But LoadFromFile raises the "Unable to open file ... No such file or directory" error.

martinrame:
I still can't find a solution, but I'm still trying.

I made this simple recursive file search, for finding part of the file. I know all files end with a number followed by .pdf, so I call:


--- 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";}};} ---FindFile('/path/to/file/', '1234.pdf');
That finds the first file that ends in '1234.pdf' and I try to open using LoadFromFile, but I still get the famous "Unable to open file..." ONLY ON FILES WITH SPECIAL CHARACTERS, like Ñ. Why I can't open the file, when FindFirst/FindNext finds it?.


--- 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";}};} ---function TTest.FindFile(const Dir: string; AMatch: string): string;                 var                                       SR: TUnicodeSearchRec;                                                                            lFiles: string;                          begin                                                                                               if FindFirst(IncludeTrailingBackslash(Dir) + '*.pdf', faAnyFile or faDirectory, SR) = 0 then        try                                                                                                 repeat                                                                                              if (SR.Attr and faDirectory) = 0 then                                                               if Pos(AMatch, SR.Name) > 0 then          begin                                                                                               lFiles := SR.Name;                                                                                with TStringList.Create do               begin                                                                                                LoadFromFile(Dir + SR.Name); // <-- Unable to open file....            end;                                                                                              break;                                                                                          end                                                                                             else if (SR.Name <> '.') and (SR.Name <> '..') then          FindFile(IncludeTrailingBackslash(Dir) + SR.Name, AMatch);  // recursive call!      until FindNext(Sr) <> 0;                                                                          Result := lFiles;    finally      FindClose(SR);    end;end; 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version