fpschultze - Howto - Batch Howto - How To Show a Progress Bar While Copying Files?


Frank-Peter Schultze's Scripting Site

Login Consultants BlogRing
Previous Site : Random Site : Next Site : List Sites
Powered by WebRingo
Main Menu
Site Search
Creative Commons License
Cool Companies
Login Consultants
Immidio | Shortcuts For Sharp Minds
My PowerShell IDE is PowerGUI
SmartFAQ is developed by The SmartFactory (http://www.smartfactory.ca), a division of InBox Solutions (http://www.inboxsolutions.net)

How To Show a Progress Bar While Copying Files?
Requested by Anonymous and Answered by Frank-Peter Schultze [webmaster] on 14-Sep-2005 23:51 (52810 reads)
"Basically, I am writing a batch program that copies 2 files to a backup folder named (current date). I want to improve this to also show dots to show some kind of activity while copying. I am thinking of using a loop but what would be my ending parameter (otherwise, it becomes an infinite loop). Do you have a better solution to this? Thanks in advance!"

The approach below executes the copy command in an additional (minimized) command window and then creates a flag file. During the file copy the main batch checks every second for the flag file and shows a period if the flag file does not exist.

@Echo Off
::Copy the first file.
Call :Pcopy "source 1" target1 /Options
::Copy the second file.
Call :Pcopy source2 "target 2" /Options
(Goto :EOF)

Set Flagfile=%TEMP%.\%RANDOM%.tmp
If Exist %Flagfile% Del %Flagfile%
Start /Min Copy %* ^& Echo.^>%Flagfile% ^& Exit
(Set /P i=Copying %1) < NUL
If Exist %Flagfile% (Goto :EOF)
::Echo period w/o carriage return/line feed
(Set /P i=.) < NUL
::Wait one second (increase no. of ping requests
::in order to wait for a longer time)
Ping -n 2 > NUL
Goto Pcopy1

Download a batch file that uses this method.


© 2000-2006 mail | Powered by XOOPS © 2001-2005 The XOOPS Project