Copying a file

Copying a file

Postby Natter » 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 ?
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 12:10 pm

Image?
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 12:24 pm

Code: Select all  Expand view

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

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 12:26 pm

Code: Select all  Expand view

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

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 12:28 pm

Code: Select all  Expand view

#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 - kapiabafwh@gmail.com
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copying a file

Postby Natter » 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
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

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

Re: Copying a file

Postby Natter » Thu Sep 02, 2021 1:00 pm

Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 1: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

Image

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copying a file

Postby Natter » Thu Sep 02, 2021 1:47 pm

Thanks, karinha
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 1: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
User avatar
karinha
 
Posts: 7794
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copying a file

Postby Natter » Thu Sep 02, 2021 7: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 ?
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

Postby karinha » Thu Sep 02, 2021 7:46 pm

look,

Code: Select all  Expand view


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

Re: Copying a file

Postby Natter » Fri Sep 03, 2021 8:58 am

it only works if the file name and path are in Latin
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Re: Copying a file

Postby Natter » 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
Natter
 
Posts: 1203
Joined: Mon May 14, 2007 9:49 am

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 56 guests