FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour CopyFile & ProgressBar
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
CopyFile & ProgressBar
Posted: Wed Dec 11, 2013 11:21 AM

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

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: CopyFile & ProgressBar
Posted: Wed Dec 11, 2013 12:43 PM
Please have a look at :

viewtopic.php?f=3&t=24166

I'm working on a painter, to create the gradient, define the size, filecopy, create a index and more ...



Best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: CopyFile & ProgressBar
Posted: Wed Dec 11, 2013 09:08 PM

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,

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: CopyFile & ProgressBar
Posted: Thu Dec 12, 2013 02:28 AM

Maybe this post can help you.

viewtopic.php?f=6t=15657hilit=copyfiles#p81071
Regards.

&&

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: CopyFile & ProgressBar
Posted: Thu Dec 12, 2013 12:51 PM
I added a second meter, to show the progress of big files.
I think, it will be the needed solution ?



best regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 244
Joined: Fri Oct 28, 2005 06:29 PM
Re: CopyFile & ProgressBar
Posted: Thu Dec 12, 2013 01:30 PM
Try this:


Code (fw): Select all Collapse
#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

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


Best regards
Alejandro
Alejandro Cebolido

Buenos Aires, Argentina

Continue the discussion