Copy file by mask

Re: Copy file by mask

Postby Enrico Maria Giordano » Thu Nov 07, 2024 8:39 am

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 view
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:
Image
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 view
Error BASE/1302  Argument error: HB_CDPSELECT


Code: Select all  Expand view
  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 )
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy file by mask

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10640
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy file by mask

Postby Enrico Maria Giordano » Thu Nov 07, 2024 11:47 am

I get that error using Harbour, not xHarbour.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy file by mask

Postby karinha » Thu Nov 07, 2024 12:56 pm

So it doesn't work Natter?
¿Entonces no funciona Natter?

Code: Select all  Expand view

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
User avatar
karinha
 
Posts: 7823
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copy file by mask

Postby Natter » Thu Nov 07, 2024 1:08 pm

Rao, Enrico - thanks, I learned how to copy such files (for xHarbour). The approximate scheme is as follows

Code: Select all  Expand view
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.
:)
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Copy file by mask

Postby nageswaragunupudi » Thu Nov 07, 2024 1:16 pm

I get that error using Harbour, not xHarbour.

I am extremely sorry.
We need to keep these REQUESTs before Main()

Code: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10640
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy file by mask

Postby nageswaragunupudi » Thu Nov 07, 2024 1: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
User avatar
nageswaragunupudi
 
Posts: 10640
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy file by mask

Postby Natter » Thu Nov 07, 2024 1:37 pm

So far, everything is working well. I had a few problematic files and they all copied fine.
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Copy file by mask

Postby Enrico Maria Giordano » Thu Nov 07, 2024 2: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. :-(
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Copy file by mask

Postby nageswaragunupudi » Thu Nov 07, 2024 2: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
User avatar
nageswaragunupudi
 
Posts: 10640
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 26 guests