Page 2 of 2
Re: Copy file by mask
Posted: Thu Nov 07, 2024 8:39 am
by Enrico Maria Giordano
nageswaragunupudi wrote:Seeking guidance from Experts.
I created files, with names encoded with different codepages like this using Harbour. (not xHarbour)
Code: Select all | Expand
function NatCreate()
local aFiles := { "Own", Chr(196)+Chr(197)+Chr(198), Chr(196)+Chr(197)+Chr(198), ;
CHR(208)+CHR(221)+CHR(222), HEXTOSTR( "E0B0AEE0B0A8E0B0B5" ) }
local cdp := { "DEWIN", "DEWIN", "RU1251", "TRWIN", "UTF8" }
FW_setunicode( .t. )
WinExec( "del c:\natfiles\src\*.*" )
AEval( aFiles, { |c,i| aFiles[ i ] := "My" + c + "File.txt" } )
xbrowser afiles
AEVAL( aFiles, <|c,i|
HB_CDPSELECT( cdp[ i ] )
HB_MEMOWRIT( "c:\natfiles\src\" + c, c )
return nil
> )
return nil
Now I try to see the directory in dos-prompt:
We can see from the image is that the command prompt is using my default OEM codepage 437 (OEM English codepage)
Still all filenames created with different codepages are displayed correctly though different from the codepage used by the command window.
How?
I understand, though I am not sure, that Windows must be storing all directory information using UTF16LE.
Request our experts to guide and enlighten.
Code: Select all | Expand
Called from: TEST1.prg => HB_CDPSELECT( 0 )
Called from: TEST1.prg => (b)NATCREATE( 15 )
Called from: TEST1.prg => AEVAL( 0 )
Called from: TEST1.prg => NATCREATE( 18 )
Re: Copy file by mask
Posted: Thu Nov 07, 2024 11:30 am
by nageswaragunupudi
As I already said, I created with Harbour but not xHarour for more than one reason.
1) xHarbour does not support "RU1251". That is the error you are getting. We may omit element no.3 from the two arrays, viz., aFiles and cdp.
2) xHarbour can not create with this kind of filenames. This is evident from the 2nd example which shows that xHarbour (to the best of my knowledge can not even read the filenames). I am seeking advice on this.
Better to create using Harbour and then solve the problem in my 2nd example first. When you advise a solution for reading, we may find a solution for writing too.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 11:47 am
by Enrico Maria Giordano
I get that error using Harbour, not xHarbour.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 12:56 pm
by karinha
So it doesn't work Natter?
¿Entonces no funciona Natter?
Code: Select all | Expand
REM NATTER.BAT
ECHO ON
CLS
COPY C:\TMP\*.TXT C:\TESTE3\ /Y
DIR C:\TESTE3
Echo .
Echo * PERFECT *
Regards, saludos.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 1:08 pm
by Natter
Rao, Enrico - thanks, I learned how to copy such files (
for xHarbour). The approximate scheme is as follows
Code: Select all | Expand
itm:=cGetFile()
if ! file (itm)
for st=1 to len(itm)
++cnt
if IsUTF8(substr(itm,st,2))
if left(strtohex(substr(itm,st,2)),1)!="D"
aadd(dim, {cnt, chr(hextonum(right(strtohex(substr(itm,st,2)),2)))})
endif
++st
endif
next
itm:=OemToAnsi(hb_UTF8ToStr(itm))
for st=len(dim) to 1 step -1
itm:=left(itm,dim[st,1]-1)+substr(itm, dim[st,1]+1)
next
? file(itm) -> .F.
FileAppend(itm, MyPath+cFileName(itm))
? file(MyPath+cFileName(itm)) -> .T.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 1:16 pm
by nageswaragunupudi
I get that error using Harbour, not xHarbour.
I am extremely sorry.
We need to keep these REQUESTs before Main()
Code: Select all | Expand
REQUEST HB_CODEPAGE_DEWIN
REQUEST HB_CODEPAGE_RU1251
REQUEST HB_CODEPAGE_TRWIN
REQUEST HB_CODEPAGE_UTF8
I normally keep REQUESTS for many codepages in my main module.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 1:27 pm
by nageswaragunupudi
Rao, Enrico - thanks, I learned how to copy such files (for xHarbour). The approximate scheme is as follows
I don't think so.
Brfore I discuss this in more detail, a few points.
Results of OemToAnsi() and AnsiToOem() differ from country to country. Depend on the default Windows codepages for OEM and ANSI. These codepages can not be changed by HB_CDPSELECT()
For example:
The differ between India, Russia and Italy.
But same in Italy, Spain, Germany and Brazil
Results of hb_StrToUtf8() and hb_Utf8ToStr() depend on the codepage set by HB_CDPSELECT() or the default, which also differs from country to country.
Let us first work on xHarbour DIRECTORY() function.
There is a reason for me to seek help of Experts like Mr. Enrico.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 1:37 pm
by Natter
So far, everything is working well. I had a few problematic files and they all copied fine.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 2:23 pm
by Enrico Maria Giordano
nageswaragunupudi wrote:There is a reason for me to seek help of Experts like Mr. Enrico.
I'm not expert with codepages at all, sorry.
Re: Copy file by mask
Posted: Thu Nov 07, 2024 2:32 pm
by nageswaragunupudi
I'm not expert with codepages at all, sorry.
Not necessary.
There is a lot you can help me.
And I am looking forward to it.
Please wait. I will make another very simple test program.