FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Copy file by mask
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 08:39 AM
nageswaragunupudi wrote:Seeking guidance from Experts.
I created files, with names encoded with different codepages like this using Harbour. (not xHarbour)
Code (fw): Select all Collapse
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 (fw): Select all Collapse
Error BASE/1302  Argument error: HB_CDPSELECT
Code (fw): Select all Collapse
   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 )
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 11:30 AM

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.

Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 11:47 AM

I get that error using Harbour, not xHarbour.

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 12:56 PM
So it doesn't work Natter?
¿Entonces no funciona Natter?
Code (fw): Select all Collapse
REM NATTER.BAT

ECHO ON
CLS

COPY C:\TMP\*.TXT C:\TESTE3\ /Y

DIR C:\TESTE3

Echo .
Echo * PERFECT *
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 01:08 PM
Rao, Enrico - thanks, I learned how to copy such files (for xHarbour). The approximate scheme is as follows
Code (fw): Select all Collapse
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.
:)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 01:16 PM
I get that error using Harbour, not xHarbour.
I am extremely sorry.
We need to keep these REQUESTs before Main()
Code (fw): Select all Collapse
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 01:27 PM
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 01:37 PM

So far, everything is working well. I had a few problematic files and they all copied fine.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 02:23 PM
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. :-(
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy file by mask
Posted: Thu Nov 07, 2024 02:32 PM
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.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion