Page 1 of 2
Copying a file
Posted: Thu Sep 02, 2021 11:28 am
by Natter
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 ?
Re: Copying a file
Posted: Thu Sep 02, 2021 12:10 pm
by karinha
Image?
Re: Copying a file
Posted: Thu Sep 02, 2021 12:24 pm
by karinha
Code: Select all | Expand
#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
Re: Copying a file
Posted: Thu Sep 02, 2021 12:26 pm
by karinha
Code: Select all | Expand
#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
Re: Copying a file
Posted: Thu Sep 02, 2021 12:28 pm
by karinha
Code: Select all | Expand
#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.
Re: Copying a file
Posted: Thu Sep 02, 2021 12:28 pm
by Natter
It can be any type of file. Problems with the header if this file was sent via whatsapp
Re: Copying a file
Posted: Thu Sep 02, 2021 12:50 pm
by karinha
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.
Re: Copying a file
Posted: Thu Sep 02, 2021 1:00 pm
by Natter
Re: Copying a file
Posted: Thu Sep 02, 2021 1:42 pm
by karinha
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.
Re: Copying a file
Posted: Thu Sep 02, 2021 1:47 pm
by Natter
Thanks, karinha
Re: Copying a file
Posted: Thu Sep 02, 2021 1:50 pm
by karinha
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.comRegards, saludos.
Re: Copying a file
Posted: Thu Sep 02, 2021 7:32 pm
by Natter
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 ?
Re: Copying a file
Posted: Thu Sep 02, 2021 7:46 pm
by karinha
look,
Code: Select all | Expand
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.
Re: Copying a file
Posted: Fri Sep 03, 2021 8:58 am
by Natter
it only works if the file name and path are in Latin
Re: Copying a file
Posted: Fri Sep 03, 2021 10:26 am
by Natter
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