WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Progress Bars

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Progress Thermometer During FileCopy

Keywords:    progress bar

Question:

How do I set up a progress bar, to show how far along a file copy is?

Answer:

Option #1: For a simple file copy status bar see the ShellOp Extender functions aStatusBar and aFileCopy.

Option #2: You will need two Winbatch scripts. The first one does the FileCopy; the second .WBT, which you will launch with the Run command just prior to your FileCopy function in your main .WBT, has the Progress Bar.

Here's the basic idea. The second .WBT sits around for a prescribed amount of time, puts up a fake progress thermometer (based on how long you anticipate it will take to do the filecopy in a worst-case scenario), and continually looks for a window title to appear.

The first .WBT does the filecopy, and when it's done, changes it's Winbatch window title to something like, "TRANSFER COMPLETED", with the Wintitle function:

;This is in the first .WBT
	FileCopy("C:\temp\sourcefile.zip", "z:\temp\destfile.zip", @false)
	Wintitle("", "TRANSFER COMPLETED")
When the second .WBT sees the window "TRANSFER COMPLETED", it exits.
;This is the second .WBT
; PROGRESS BAR PROGRAM

DKBLUE="0,0,128"
BLUE="0,0,255"
LTGRAY="192,192,192"
GRAY="128,128,128"
DKGRAY="64,64,64"
GREEN="0,255,0"
RED="255,0,0"
BLACK="0,0,0"
WHITE="255,255,255"
YELLOW="255,255,0"
counter=1


BoxesUp("100,100,900,900",@NORMAL)
     rectutext="100,100,1000,900"
     rectTherm="200,350,800,650"
     rectButton="0,0,100,100"
     rectThermLine1="100,550,900,550"
     rectThermLine2="900,550,900,800"
     rectThermLine3="900,800,100,800"
     rectThermLine4="100,800,100,550"
     ThermPenWidth=20
     rectThermText1="100,50,1000,199"
     rectThermPercent="490,625,550,725"
     rectTopHalf="0,0,1000,210"
     rectBotHalf="0,210,1000,1000" 
     rectTitle="100,20,900,170"
     rectTitleText="10,100,790,875"
     TitleHeight=950
     rectNote="85,30,900,250" ;this is the top text bkg
     NoteHeight=400
     rectNoteText="55,350,500,500"; top text placement for dont reboot
     rectnoteline1="0,0,1000,0"
     rectNoteline2="1000,1000,1000,0"
     rectNoteLine3="0,1000,1000,1000"
     rectNoteLine4="0,0,0,1000"
     notepenwidth=20
     rectnoteline1b="40,150,960,150"
     rectNoteline2b="960,840,960,150"
     rectNoteLine3b="40,840,960,840"
     rectNoteLine4b="40,150,40,840"
     notepenwidthb=10
     Thermid=3
     Noteid=4
	     ; Make main window look nice
	     BoxColor(1,"128,0,0",1)
	     BoxDrawRect(1,"0,0,1000,1000",2)
	     BoxCaption(1,"YOUR COMPANY NAME")
	     

	     
   ;;;;Do note box
	     BoxNew(Noteid,rectNote,1)
	     BoxColor(Noteid,LTGRAY,0)	     ; Light Gray no gradient
	     BoxDrawRect(Noteid,"",2)
	     
	     BoxTextFont(Noteid,"Arial",NoteHeight,170,0)
	     BoxTextColor(Noteid,RED)
	     
	     BoxPen(Noteid,WHITE,notepenwidth)
	     boxdrawline(Noteid,rectNoteLine1)
	     boxdrawline(Noteid,rectNoteLine4)
	     BoxPen(Noteid,GRAY,notepenwidth)
	     boxdrawline(Noteid,rectNoteLine2)
	     boxdrawline(Noteid,rectNoteLine3)
	     BoxPen(Noteid,WHITE,notepenwidthb)
	     boxdrawline(Noteid,rectNoteLine2b)
	     boxdrawline(Noteid,rectNoteLine3b)
	     BoxPen(Noteid,GRAY,notepenwidthb)
	     boxdrawline(Noteid,rectNoteLine1b)
	     boxdrawline(Noteid,rectNoteLine4b)
	     
	     BoxDataTag(Noteid,"NOTE")
	     BoxDrawText(Noteid,rectNoteText,"",1,4)
	     
	     
	     
	     ;Draw thermometer outline
	     BoxNew(Thermid,rectTherm,2)
	     BoxUpdates(Thermid,0)
	     BoxCaption(Thermid,"Put Something in Here.")
	     BoxColor(Thermid,LTGRAY,0)
	     BoxDrawRect(Thermid,"",2)
	     ; Draw updating thermometer here
	     ; there are 3 virtual pixels per percent
	     ; we have to draw 3 boxes and some text...
	     BoxDataTag(Thermid,"Hello")
	     BoxCaption(Thermid,"Transmitting File...Please Be Patient!")
	     
 while @true	    
		counter=(counter+1)
		FilesToCopy=counter*30; use 30 for 30 seconds until final launch when set to est. time
	     
	     for FilesCopied=1 to FilesToCopy
		BoxDataClear(Thermid,"Hello")
		BoxUpdates(Thermid,0)
		BoxColor(Thermid,GREEN,0)
		xxx= 100+((800*FilesCopied)/FilesToCopy)
		per=(100.0*FilesCopied)/FilesToCopy
		per=Int(per)
		BoxDrawRect(Thermid,"104,554,%xxx%,796",2)
		BoxColor(Thermid,GRAY,0)
		BoxDrawRect(Thermid,"%xxx%,554,896,796",2)
		BoxPen(Thermid,BLACK,ThermPenWidth)
		boxdrawline(Thermid,rectThermLine1)
		boxdrawline(Thermid,rectThermLine2)
		boxdrawline(Thermid,rectThermLine3)
		boxdrawline(Thermid,rectThermLine4)
		
		if per<50 then BoxTextColor(Thermid,WHITE)
		BoxDrawText(Thermid,rectThermPercent,"%per%%%",0,0)
		BoxTextColor(Thermid,BLACK)
		BoxColor(Thermid,LTGRAY,0)
		BoxDrawText(Thermid,rectThermText1,"Transmission Progress: %FilesCopied%",1,0)
		BoxDataClear(NoteId,"NOTE");;;
		BoxTextFont(Noteid,"Arial",240,0,0)
		BoxDrawText(Noteid,rectNoteText,"DO NOT REBOOT OR RESET COMPUTER!",1,4);;;
		BoxUpdates(Thermid,2)
		TimeDelay(Random(1.0))	 ;Fake passage of time

		if WinExist("TRANSFER COMPLETED")
		   boxdestroy(1) 
		   exit
		endif

	    next

	    ;BoxTextColor(Noteid,GREEN)	       
	     ;BoxDrawText(Noteid,rectNoteText," ",1,4)	      
	     ;BoxDestroy(Thermid)
	     ;BoxDestroy(Noteid)

endwhile



 


Article ID:   W12749
Filename:   Another Progress Bar during FileCopy.txt
File Created: 2001:01:03:09:14:40
Last Updated: 2001:01:03:09:14:40