Filecopy with progressbar

Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Filecopy with progressbar

Post by Otto »

Does someone please have a filecopy with a progressbar routine.

Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Maurizio
Posts: 705
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: Filecopy with progressbar

Post by Maurizio »

Code: Select all

#include "FWCE.ch"

//----------------------------------------------------------------------------//
function Main()
 local oWnd, oPgr ,oTimer

   DEFINE WINDOW oWnd TITLE "Progress Bars"

     DEFINE TIMER oTimer OF oWnd INTERVAL  500  ;
            ACTION StartCopy(oPgr,oWnd,oTimer)
            
      ACTIVATE TIMER oTimer

     @ 2, 8 SAY "FiveWin for Pocket PC" OF oWnd SIZE 150, 20
     @ 4, 6 PROGRESS oPgr POS 0 OF oWnd SIZE 150, 15
     @ 9, 6 BUTTON "Fine" OF oWnd SIZE 180, 30  ACTION  oWnd:End()
   ACTIVATE WINDOW oWnd


return nil

Function StartCopy(oMeter1 ,oWnd,oTimer)

   local n
   local hSource, hTarget
    Local nBufSize := 80000
   local nBytes, nFile := 0, nTotal := 0
   local nTotSize := 0
    Local cSource := "\\server\ori\risto.exe"
    Local cDest   := "risto\risto.EXE"
    Local nLen := 0
    Local lOk := .F.
    Local cBuffer := ""
    Local oIni
    Local cDir  := curdir()+ "\"
    Local cFile := cDir + "COPY.TXT"
    Local cText := "\\server\ori\risto.exe" + CRLF + ;
                  "risto\risto.EXE"
    Local nX := 1
    Local nR := 1

   oTimer:DeActivate()

    IF ! file(cFile)
        MemoWrit( cFile, cText )
    ENDIF
    cText  := memoread(cFile)
    nR := mlcount(cText)
    cSource := memoline(cText,,1)
    cDest   := alltrim(cDir + memoline(cText,,2))

    cSource := alltrim(cSource)
    IF ! file(cSource)
      oTimer:Activate()
        Return nil
    ENDIF

      hTarget = FCreate( cDest )
        IF hTarget == - 1
         oTimer:Activate()
            return nil
        ENDIF
      cBuffer := Space( nBufSize )

      hSource = FOpen( cSource )
        IF hSource == -1
         oTimer:Activate()
            return nil
        ENDIF

      nLen :=  FSeek( hSource, 0, 2 ) / nBufSize
      FSeek( hSource, 0, 0 )
        oMeter1:SetRange( 0, nLen)

      nFile := 0
      while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
          FWrite( hTarget, cBuffer, nBytes )
          oMeter1:nPosition ++
             oMeter1:Refresh()
            lOk := .T.
      end
      FClose( hSource )
      FClose( hTarget )

      IF lOk
         IF FERASE(cSource) == - 1
              MsgInfo("Non cancellato")
         ELSE
              // MsgInfo("File copiato")
         ENDIF
      ENDIF


     oMeter1:nPosition := 0
      oMeter1:Refresh()

     oTimer:Activate()

return nil
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Filecopy with progressbar

Post by Otto »

Maurizio, thank you very much.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
Post Reply