Progress bar While copying

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Progress bar While copying

#1 Post by abc0502 » 04 Jul 2012 05:42

Hi, I'm trying to make a progress bar animate while copying my files,
I'm making a backup batch files and i have the animation code for the progress bar but can't make them run in the same time
i tried the ULTIMATE WHILE LOOP of Aacini but couldn't make it work
Any help Appreciated
thanks

Progress Bar Code:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set Counter=0
set Schalter=2
set Width=0

:1
title Animation Box - Installation
set /a Counter=%Counter% + 1
set /a Display=%Counter% / 2
FOR /L %%A IN (1,1,%Display%) DO (
   set Display=!Display!²
)
cls
echo            New files are copied...                  %Counter%%%
echo     ²!Display:~2,47!
ping localhost -n 1 >nul
if "%Counter%" == "100" goto :1-End
goto :1
:1-End
echo.
echo Installation complete.
pause >nul
EXIT /B


and Copy Codes:

Code: Select all

   :: Get USB Drive Letter
SET "ID_1=C07325E8"
FOR /F "tokens=1 delims= " %%! IN ('WMIC LOGICALDISK LIST FULL ^|FINDstr /c:%ID_1%') DO SET drv=%%!

IF NOT EXIST "%drv%\home\docs\BU\%date:/=%" MD "%drv%\home\docs\BU\%date:/=%" >nul
copy /y "%drv%\home\DataBase\apps\Database.kdb" "%drv%\home\docs\BU\%date:/=%\Kee-pass_Database.kdb" >nul
copy /y "%drv%\home\DataBase\apps\The_Guide.gde" "%drv%\home\docs\BU\%date:/=%\The_guide.gde" >nul
copy /y "%drv%\bin\executor.ini" "%drv%\home\docs\BU\%date:/=%\executor.ini" >nul
copy /y "%drv%\bin\Keywords.exc" "%drv%\home\docs\BU\%date:/=%\Keywords.exc" >nul

MD "%drv%\home\docs\BU\%date:/=%\Notes" >nul
xcopy /y /E "%drv%\home\bin1\InDeep_Notes\Data\Notes\*.*" "%drv%\home\docs\BU\%date:/=%\Notes\*.*" >nul

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Progress bar While copying

#2 Post by Dos_Probie » 05 Jul 2012 05:42

Don't know about running at same time but if you just want to have "eye candy" with your backup
you could add the progress bar code to the backend of your existing batch file.
8)

Code: Select all

@echo off&color a
setlocal EnableDelayedExpansion
title [ USB BACK-UP ]

   :: Get USB Drive Letter
SET "ID_1=C07325E8"
FOR /F "tokens=1 delims= " %%! IN ('WMIC LOGICALDISK LIST FULL ^|FINDstr /c:%ID_1%') DO SET drv=%%!

IF NOT EXIST "%drv%\home\docs\BU\%date:/=%" MD "%drv%\home\docs\BU\%date:/=%" >nul
copy /y "%drv%\home\DataBase\apps\Database.kdb" "%drv%\home\docs\BU\%date:/=%\Kee-pass_Database.kdb" >nul
copy /y "%drv%\home\DataBase\apps\The_Guide.gde" "%drv%\home\docs\BU\%date:/=%\The_guide.gde" >nul
copy /y "%drv%\bin\executor.ini" "%drv%\home\docs\BU\%date:/=%\executor.ini" >nul
copy /y "%drv%\bin\Keywords.exc" "%drv%\home\docs\BU\%date:/=%\Keywords.exc" >nul

MD "%drv%\home\docs\BU\%date:/=%\Notes" >nul
xcopy /y /E "%drv%\home\bin1\InDeep_Notes\Data\Notes\*.*" "%drv%\home\docs\BU\%date:/=%\Notes\*.*" >nul
goto :progressbar

:progressbar
set Counter=0
set Schalter=2
set Width=0

:1
title [ FINALIZING - BACKUP ]
set /a Counter=%Counter% + 1
set /a Display=%Counter% / 2
FOR /L %%A IN (1,1,%Display%) DO (
   set Display=!Display!²
)
cls
echo            Backing Up Files and Folders...                  %Counter%%%
echo     ²!Display:~2,47!
ping localhost -n 1 >nul
if "%Counter%" == "100" goto :1-End
goto :1
:1-End
echo.
echo.
echo BACKUP HAS COMPLETED SUCCESSFULLY..
echo.
echo.
echo Press [ANY KEY] to EXIT.
pause >nul
exit /b

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Progress bar While copying

#3 Post by abc0502 » 06 Jul 2012 03:08

Thanks, Dos_Probie I thin I will do that.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Progress bar While copying

#4 Post by Dos_Probie » 06 Jul 2012 14:09

Actually I took your progress bar code and added it to my backup file with
date and time stamp 12hr format folders and it LQQKS pretty good now.. 8)

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Progress bar While copying

#5 Post by Aacini » 06 Jul 2012 18:40

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set WildCard=*.*
if "%1" neq "" set WildCard=%1\*.*
set Total=0
for %%a in (%WildCard%) do set /A Total+=1
if %Total% leq 60 (
   set /A Unit=1, UnitSize=60/Total
) else (
   set /A Unit=Total/60+1, UnitSize=1
)
set UnitBar=
for /L %%a in (1,1,%UnitSize%) do set UnitBar=!UnitBar!²

title Animation Box - Installation
set Display=
set File=0
for %%a in (%WildCard%) do (
   set /A File+=1, FileMod=File %% Unit, Percent=File*100/Total
   if !FileMod! equ 0 set Display=!Display!%UnitBar%
   cls
   echo Copying file: %%a
   echo !Percent!%%    !Display!
   ping localhost -n 1 >nul
)

echo/
echo Installation complete.
pause >nul
EXIT /B

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Progress bar While copying

#6 Post by abc0502 » 07 Jul 2012 02:40

@Dos_Probie, will this code is not mine i found it in a file that has many tricks i don't remember where i get it but mostly from here,
and Thanks Aacini but your code is way out of my head :)
where should i put the files that will be copied and the distenation folder?? :?
The files are in about three or four differant locations not in one place.

joakim
Posts: 24
Joined: 07 Mar 2012 12:08

Re: Progress bar While copying

#7 Post by joakim » 07 Jul 2012 05:21

take a look at this, i hope it helps =P

"http://www.youtube.com/watch?v=6L3h0KP6_x0&list=UUDkMdK1D-23knr9qCI7JmCw&index=7&feature=plcp"

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Progress bar While copying

#8 Post by abc0502 » 07 Jul 2012 06:55

thanks joakim but my problem not in the progress bar, it's in how i copy and show the progress bar at the same time
Aacini has a cool progress bar also it show you the files that being copied "or supposed to be" but how i make it copy files for real :?:

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Progress bar While copying

#9 Post by einstein1969 » 07 Jul 2012 07:56

abc0502 wrote:thanks joakim but my problem not in the progress bar, it's in how i copy and show the progress bar at the same time
Aacini has a cool progress bar also it show you the files that being copied "or supposed to be" but how i make it copy files for real :?:


Code: Select all

:: Get USB Drive Letter
SET "ID_1=C07325E8"
FOR /F "tokens=1 delims= " %%! IN ('WMIC LOGICALDISK LIST FULL ^|FINDstr /c:%ID_1%') DO SET drv=%%!

IF NOT EXIST "%drv%\home\docs\BU\%date:/=%" MD "%drv%\home\docs\BU\%date:/=%" >nul
copy /y "%drv%\home\DataBase\apps\Database.kdb" "%drv%\home\docs\BU\%date:/=%\Kee-pass_Database.kdb" >nul
copy /y "%drv%\home\DataBase\apps\The_Guide.gde" "%drv%\home\docs\BU\%date:/=%\The_guide.gde" >nul
copy /y "%drv%\bin\executor.ini" "%drv%\home\docs\BU\%date:/=%\executor.ini" >nul
copy /y "%drv%\bin\Keywords.exc" "%drv%\home\docs\BU\%date:/=%\Keywords.exc" >nul

MD "%drv%\home\docs\BU\%date:/=%\Notes" >nul
xcopy /y /E "%drv%\home\bin1\InDeep_Notes\Data\Notes\*.*" "%drv%\home\docs\BU\%date:/=%\Notes\*.*" >nul




is not the solution but to clarify
========================

your code do :

1) find destination of backup
2) make destination folder
3) copy files.

The progress bar needs to "count the progress"

How to count the progress?

Need a "total" and then you need to count progress.

In the code shown by Aacini there is a mechanism for counting a total, but it needs to adapt.

Must count the number of backup files for the "total".

Then you need to count the backup progress.

Then your code need:

1) find destination of backup
2) make destination folder
2) counting number of file (or BYTES) to backup (the total)
3) copy files and 3a) while copying counting and 3b) show the progress

You need to implement 2) and 3a)

For xcopy there is a paramter that show the file to copying "/L" ,this for counting in step 2)

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Progress bar While copying

#10 Post by Aacini » 07 Jul 2012 09:50

Code: Select all

@echo off
setlocal EnableDelayedExpansion

   :: Get USB Drive Letter
SET "ID_1=C07325E8"
FOR /F %%! IN ('WMIC LOGICALDISK LIST FULL ^|FINDstr /c:%ID_1%') DO SET drv=%%!
set "target=%drv%\home\docs\BU\%date:/=%"

IF NOT EXIST "%target%" MD "%target%" >nul
MD "%target%\Notes" >nul

rem Create a list of *INDIVIDUAL* files to copy
set "file[1]=%drv%\home\DataBase\apps\Database.kdb"
set "file[2]=%drv%\home\DataBase\apps\The_Guide.gde"
set "file[3]=%drv%\bin\executor.ini"
set "file[4]=%drv%\bin\Keywords.exc"
set Total=4
for %%a in ("%drv%\home\bin1\InDeep_Notes\Data\Notes\*.*") do (
   set /A Total+=1
   set "file[!Total!]=%%a"
)

if %Total% leq 60 (
   set /A Unit=1, UnitSize=60/Total
) else (
   set /A Unit=Total/60+1, UnitSize=1
)
set UnitBar=
for /L %%a in (1,1,%UnitSize%) do set UnitBar=!UnitBar!²

title Animation Box - Installation
set Display=
for /L %%i in (1,1,%Total%) do (
   set /A FileMod=%%i %% Unit, Percent=%%i*100/Total
   if !FileMod! equ 0 set Display=!Display!%UnitBar%
   cls
   echo Copying file: !file[%%i]!
   echo !Percent!%%    !Display!

   if %%i leq 4 (
      copy /y "!file[%%i]!" "%target%" >nul
   ) else (
      xcopy /y /E "!file[%%i]!" "%target%\Notes" >nul
   )
)

rem Final adjustment for different-named file
ren "%target%\Database.kbd" Kee-pass_Database.kbd

echo/
echo Installation complete.
pause >nul
EXIT /B

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Progress bar While copying

#11 Post by abc0502 » 07 Jul 2012 11:19

@Aacini, Thanks alot for your help the code work :D
but i have one more question, the note folder have more folders in it and every folder have txt files
the code copy the content of the notes folder but not the content of other folders in it, i tried adding /S switch
but not workin... any idea

thanks again and sorry for asking too many ... :oops:

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Progress bar While copying

#12 Post by abc0502 » 07 Jul 2012 12:11

Hi Aacini I found a way it's not the same you made the batch but it's ok at least it work
i modified the code to be like this
@echo off
setlocal EnableDelayedExpansion

:: Get USB Drive Letter
SET "ID_1=C07325E8"
FOR /F %%! IN ('WMIC LOGICALDISK LIST FULL ^|FINDstr /c:%ID_1%') DO SET drv=%%!
set "target=%drv%\home\docs\BU\%date:/=%"

IF NOT EXIST "%target%" MD "%target%" >nul
MD "%target%\Notes" >nul

rem Create a list of *INDIVIDUAL* files to copy
set "file[1]=%drv%\home\bin1\InDeep_Notes\Data\Notes\*.*"
set "file[2]=%drv%\home\DataBase\apps\Database.kdb"
set "file[3]=%drv%\home\DataBase\apps\The_Guide.gde"
set "file[4]=%drv%\bin\executor.ini"
set "file[5]=%drv%\bin\Keywords.exc"
set Total=5

if %Total% leq 60 (
set /A Unit=1, UnitSize=60/Total
) else (
set /A Unit=Total/60+1, UnitSize=1
)
set UnitBar=
for /L %%a in (1,1,%UnitSize%) do set UnitBar=!UnitBar!²

title Animation Box - Installation
set Display=
for /L %%i in (1,1,%Total%) do (
set /A FileMod=%%i %% Unit, Percent=%%i*100/Total
if !FileMod! equ 0 set Display=!Display!%UnitBar%
cls
echo Copying file: !file[%%i]!
echo !Percent!%% !Display!

if %%i equ 1 (
xcopy /y /E "!file[%%i]!" "%target%\Notes" >nul
) else (
copy /y "!file[%%i]!" "%target%" >nul
)
)

echo/
echo Installation complete.
pause >nul
EXIT /B

All the changes in RED

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Progress bar While copying

#13 Post by einstein1969 » 07 Jul 2012 16:28

The problem is xcopy...

There is no chance to capture output when copy or is very difficult... Need the expert!

I worked for solution and i found 3 or more solution.

The first in my tests have not failed but need trick other the higher priority trick. (xp sp2 italian)

Code: Select all

@echo off

if "%1" equ "progress" goto :progress

set "sourcedir=c:\Documents and Settings\fra\Desktop\Tools-Utility-Programmi-ProgrammiPortabili"
set "targetdir=d:\TEMP\pppp"
rem option /D do not work well. Need a trick
set xcopyoptions=/I /e /h /y /V

rem calculate total

for /f %%C in ('"xcopy %xcopyoptions% /L "%sourcedir%" "%targetdir%"" ^| find "\" /C') do set /a total=%%C

rem xcopying...

xcopy %xcopyoptions% "%sourcedir%" "%targetdir%" | more | start /HIGH /B cmd /c %0 progress

pause

goto :eof

:progress

setlocal EnableDelayedExpansion

set /a counter=0
set "old_ln="

for /L %%n in (1 0 1) do (

   set "ln="
   set /p "ln="

   set /a "inc=50*Counter/total"

   set "bar=                                                  "
   FOR /L %%A IN (1 1 !inc!) DO set "bar=±!bar!"

   cls
   echo       Files copying...                    !Counter!/%total%
   echo(
   echo     ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
   echo     ³ !bar:~0,50! ³
   echo     ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
   echo(

   if defined ln ( set /a counter+=1 & echo "!ln!" & set "old_ln=!ln!" ) else ( echo "!old_ln!" )

   rem by jeb
   if !counter! GTR %total% call :HALT

)

exit /b

goto :eof


:Halt
call :_halt 2> NUL
:_halt
()
goto :eof

Post Reply