Hi,
I need option to copy files and use progress bar while copying
Best regards,
Hi,
I need option to copy files and use progress bar while copying
Best regards,

Uwe,
Thanks for reply
Nice program but that is not what i need
Program use: CopyFile( "&FromFile", "&ToDir", .f. )
i need to find a way to use progress bar while copying a single file
For example i need to have a view while copying a file of 500mb which is giong long time
and i am not sure is program working or not.
I have try to use TIMER and read copyed bytes but timer is not functioning until CopyFile() is not finished ...
really program is dead while copying file.
I have try to use lowlevel functions fopen(), fread(), fcreate(), fwrite() ... that is good for text files but not for binary files.
Some other sugestions please ?
Best regards,

#Include "FiveWin.ch"
Static lCancel
//-------------------------------------------------------------------------------------//
Function Main()
xCopy( "freeimage.dll", "freeimage.BAK" )
Return NIL
//-------------------------------------------------------------------------------------//
Function xCopy( cSource, cTarget )
local oDlg
local oMtr
local oText
local oBtn
local oFont
local lEnd := .f.
local nVal := 0
local cMsg := "Copiando archivo " + Upper( cSource ) + " a " + Upper( cTarget )
lCancel := .F.
DEFINE FONT oFont NAME GetSysFont() SIZE 0, -8
DEFINE DIALOG oDlg FROM 5, 5 TO 13, 45 TITLE "Copy file" FONT oFont
@ 0.2, 0.5 SAY oText VAR cMsg SIZE 130, 10 OF oDlg
@ 1.3, 0.5 PROGRESS oMtr SIZE 150, 10 OF oDlg
@ 2.2, 10.4 BUTTON oBtn PROMPT "&Cancel" OF oDlg ;
ACTION ( lEnd:= .T., lCancel:= .T. ) SIZE 32, 11
oDlg:bStart := { || CopyFile( cSource, cTarget, oMtr, lCancel ), lEnd := .T., oDlg:End() }
ACTIVATE DIALOG oDlg;
CENTERED;
VALID lEnd
oFont:End()
Return lCancel
//-------------------------------------------------------------------------------------//
Function CopyFile( cSource, cTarget, oMtr )
Local nBufSize := 64000
Local hSource
Local hTarget
Local cBuffer := Space( nBufSize )
Local nTotal := 0
Local nBytes := 0
Local lOK := .T.
Local lEnd := .F.
Local nCnt := 0
If !File( cSource )
MsgStop( "El archivo " + cSource + " no existe!", "Error!" )
Return .F.
EndIf
If fError() != 0
MsgStop( "Error intentando abrir el archivo " + cSource + "!", "Error!" )
Return .F.
EndIf
CursorWait()
hSource := fOpen( cSource )
nTotal += fSeek( hSource, 0, 2 )
hTarget := fCreate( cTarget )
fSeek( hSource, 0, 0 )
oMtr:SetRange( 0, 100 )
Do While !lEnd
nBytes := fRead( hSource, @cBuffer, nBufSize )
nCnt := nCnt + nBytes
If fWrite( hTarget, cBuffer, nBytes ) < nBytes
lEnd := .T.
lOk := .F.
Else
lEnd := ( nBytes == 0 )
EndIf
If lCancel
lOk := .F.
EXIT
EndIf
SysRefresh()
oMtr:nPosition := Round( nCnt / nTotal * 100, 0 )
EndDo
FClose( hSource )
FClose( hTarget )
SysRefresh()
CursorArrow()
If lCancel
FErase( cTarget ) // Borramos archivo parcialmente copiado
EndIf
Return lOk
//-------------------------------------------------------------------------------------//