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

fpschultze

Frank-Peter Schultze's Scripting Site

WebRing
Login Consultants BlogRing
Previous Site : Random Site : Next Site : List Sites
Powered by WebRingo
Main Menu
Site Search
License
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 15-Sep-2005 01:51 (29536 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)

:Pcopy
Set Flagfile=%TEMP%.\%RANDOM%.tmp
If Exist %Flagfile% Del %Flagfile%
Start /Min Copy %* ^& Echo.^>%Flagfile% ^& Exit
(Set /P i=Copying %1) < NUL
:Pcopy1
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 127.0.0.1 > NUL
Goto Pcopy1

Download a batch file that uses this method.



 

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