FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Copying a file
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Copying a file
Posted: Thu Sep 02, 2021 11:28 AM

Hi,

There is a file. There are unicode characters in the name of this file. I need to copy this file to another disk. How can I do this ?

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 12:10 PM

Image?

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 12:24 PM
Code (fw): Select all Collapse
#include "FiveWin.ch"

FUNCTION Main()

   LOCAL cSourceFile := "C:\FWH1701\SAMPLES\TUTOR04.PRG"
   LOCAL cTargetFile := "C:\TEMP\TURO04.TXT"

   ? "Copiar de", cSourceFile, "Para", cTargetFile, "..."

   ? "Copiado", FileCopy( cSourceFile, cTargetFile ), "bytes"

RETURN NIL
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 12:26 PM
Code (fw): Select all Collapse
#Include "FiveWin.ch"

static oWnd

//----------------------------------------------------------------//

FUNCTION Main()

   LOCAL oBar, cOrigen, cDestino

   cOrigen  := Curdrive()+":\fwh1701\samples\*.prg"

   cDestino := Curdrive()+":\backup\"


   DEFINE WINDOW oWnd TITLE "Copiar Archivos"

   DEFINE BUTTONBAR oBar _3D OF oWnd

   DEFINE BUTTON OF oBar ACTION( Copiar( cOrigen, cDestino ), oWnd:End() )

   SET MESSAGE OF oWnd TO "Copiar Archivos" NOINSET CLOCK DATE KEYBOARD

   ACTIVATE WINDOW oWnd CENTER

RETURN NIL

//----------------------------------------------------------------//

FUNCTION Copiar( cOrigen, cDestino )

   LOCAL oFs

   If .not. Lisdir( cDestino )
      LMkdir( cDestino )
   Endif

   CURSORWAIT()

   oFs   := CreateObject( "Scripting.FileSystemObject" )

   // oFs:CopyFile( "z:\systems\xml\*.xml" , "r:\backups\systems\xml\", .t. ) // .t. for overwrite

   oFs:CopyFile( cOrigen, cDestino, .T. ) // .t. for overwrite

   CURSORARROW()

   ? "Pronto..."

RETURN NIL
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 12:28 PM
Code (fw): Select all Collapse
#Include "FiveWin.ch"

// Destino do Arquivo:
STATIC cTarget := "C:                                 "

FUNCTION Main()

   cTarget = AllTrim( cTarget )

   // WinExec( "COPIAR.BAT", 0 )  // COPIAR.BAT

   // DIRETO VIA FIVEWIN.
   LZCopyFile( "CUSTOMER.DBF", cTarget + "\IMPREL\RONUEL.DBF" )

   ? [PRONTO, COPIADO!]

RETURN NIL

// FIN / END - By Joao Santos - <!-- e --><a href="mailto:kapiabafwh@gmail.com">kapiabafwh@gmail.com</a><!-- e -->


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: Copying a file
Posted: Thu Sep 02, 2021 12:28 PM

It can be any type of file. Problems with the header if this file was sent via whatsapp

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 12:50 PM

Sorry I do not understand. file was sent via whatsapp? Do you have this file for testing? Make it available for download, yes?
Put in Mega Upload for download and test please.

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: Copying a file
Posted: Thu Sep 02, 2021 01:00 PM
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 01:42 PM
Natter wrote:https://cloud.mail.ru/public/hiDS/DNt1MjWHS


Hello Natter, unfortunately Windows in Portuguese does not understand how to Write in Russian. I regret not being able to help. What I could do is save the file As... And rename it... But I don't think that's what you want.

https://i.imgur.com/EGPMOch.png



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: Copying a file
Posted: Thu Sep 02, 2021 01:47 PM

Thanks, karinha

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 01:50 PM

If you can, send the original file written in Russian to my email so I can see if it saves in the source language and test it.

kapiabafwh@gmail.com

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: Copying a file
Posted: Thu Sep 02, 2021 07:32 PM
Dim GetShortFileName As StringDim ShortFileName As StringPrivate Declare Function GetShortPathName Lib "kernel32"
Alias "GetShortPathNameA" (ByVal longPath As String, ByVal shortPath As String, ByVal shortBufferSize As Int32) As Int32

I understand that you can get the alias of a file using the GetShortFileName function. How to implement it on xharbour ?
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Copying a file
Posted: Thu Sep 02, 2021 07:46 PM
look,

Code (fw): Select all Collapse
   LOCAL cPathSource := StrCapFirst( cFilePath( GetModuleFileName( GetInstance() ) ) + cFolderBK )
   LOCAL cFile       := ""

   cPathSource := cShortName( cPathSource )

   // cFile := cGetFile( "ZipFile | *.zip", "Pasta e Nome do Arquivo Para Fazer o Backup", 1, cPathSource, .T., .T. )
   cFile := cGetFile( "ZipFile | *.zip", "Pasta e Nome do Arquivo Para Backup", 1, LFN2SFN(cPathSource), .T., .T. )

.OR.

   ::cDataDir  := LFN2SFN(Alltrim(GetVV("oApp", "cDataDir"  , ::cDataDir   ) ))
   ::cLocalDir := LFN2SFN(Alltrim(GetVV("oApp", "cLocalDir" , ::cLocalDir  ) ))
   ::cUpdateDir:= LFN2SFN(Alltrim(GetVV("oApp", "cUpdateDir", ::cUpdateDir ) ))

.OR.

    cPRGPATH := cFILEPATH(GETMODULEFILENAME(GETINSTANCE()))
    cPRGPATH := cShortName(cPRGPATH)  //-> Modified / Modificado al final


/*
 *  SPN.PRG
 *
 *  cShortName() - FilePath Long to Short (GetShortPathNameA())
 *
 *  Soporte a Funciones del Api de Windows
 *
 *  Andrade A. Daniel - 2002
 *  Rosario, Argentina
 *
 *  Libre Distribución
 */

/*
 *  cShortName()
 */

FUNCTION cShortName( cLong )

    Local   cShort  := Space(164) + Chr(0)
    Local   nBuffer := 164
    Local   nLen

    nLen    := GetSPName( cLong, @cShort, nBuffer )

    cShort  := Left( cShort, nLen )

RETURN( cShort )

// Windows Api
DLL32 STATIC FUNCTION GetSPName( lpszLongPath AS STRING, lpszShortPath AS STRING, lBuffer AS LONG ) ;
      AS LONG PASCAL FROM "GetShortPathNameA" LIB "kernel32"


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: Copying a file
Posted: Fri Sep 03, 2021 08:58 AM

it only works if the file name and path are in Latin

Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Copying a file
Posted: Fri Sep 03, 2021 10:26 AM
If the file name contains unicode characters that have no analogues in ansi (in my case, this is « and »), then the function of working with files does not work