Chimaera
Hi
Im messing with this atm that i found on the net
Code: Select all
@echo off
echo.
echo.
setlocal
set COUNT=0
set MAXCOUNT=1000
set SECONDS=1
:LOOP
title "\\"
call :WAIT
title "||"
call :WAIT
title "//"
call :WAIT
title "--"
call :WAIT
if /i "%COUNT%" equ "%MAXCOUNT%" goto :EXIT
set /a count+=1
echo %COUNT%
goto :LOOP
:WAIT
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
goto :EOF
:EXIT
title FIN!
endlocal
the above code does a count but its down the page i want it one one line across the page, the twirly bit in the header of the batch really isnt that important
But i want the count to increase relative to the job its doing so it would need to assess how big the job is and tailor itself accordingly
The robo command i use would be like this
ROBOCOPY %_backup_source% %_backup_dest% %_back_what% %_robo_vista_1%
but on different machines the data size would be different so the start and finish values would be different in size so it has to reach 100% for eg when the file finishes.
i wonder if tasklist was the way to go but i couldnt work out what the filters did for window title eg
tasklist Windowtitle eq, ne mywindow name
assuming thats the right way to use it, but can it read the window its called from? and give me the progress indicator i need?
it would be nice to just have a line in the batch that increase as the batch progresses
so
* to ** to *** etc etc
or can i do
set _indicator1=*
set _indicator1=**
set _indicator1=***
set _indicator1=****
set _indicator1=*****
and have some way of swopping down the list as the file progresses
anyway back to looking for an answer
thanks for any pointers
----------------------------
20 Jan 2010 00:42
bluesxman
The concept intrigued me, so I came up with the following script. I've not tested it thoroughly and I'm sure it could be optimised in a couple of places, but it seems to work for me.
:: Notes ::
Works based on the number of files to be copied, rather than the space they occupy.
Should also detect if the robocopy process has ended while there are still files to copy.
Calculates progress by repeatedly comparing source to target, so if new files are appearing at source during the copy the bar might backstep; it will also falsely report an abort when the robocopy process exits.
Accuracy suffers a little due to the rounding by the "set /a" command (but not be enough to worry about).
Code: Select all
@echo off
set "source=e:\test\source"
set "target=e:\test\target"
set "rc=robocopy.exe"
set "rc.command=%rc% "%source%." "%target%." /s"
set "bar.width=20"
set "bar.char=*"
set "bar.backchar= "
set "bar.size=0"
set "bar.back="
set "bar.del="
set "bar.position=0"
set "loop.delay=5"
set "done=0"
set "total=1"
set "abort="
set "window.title=%rc%_%date%_%time: =0%"
echo:START
REM spawn the robocopy command with a (hopefully) unique window title that we'll need later
start /min "%window.title%" %rc.command%
REM draw the empty bar
for /l %%a in (1,1,%bar.width%) do (call set "bar.back=%%bar.back%%%bar.backchar%")
call set "bar.del=%%bar.back:%bar.backchar%=%%"
set /p "out=[%bar.back%]%bar.del%" <nul
set /a loop.delay+=1
title Please stand by...
call :loop
echo:
if defined abort (echo:ABORT) ELSE (echo:END)
pause
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::
:loop
:::::::::::::::::::::::::::::::::::::::::::::::::::::
set bar=
REM if all the files have been copied, draw a full bar (in case it didn't get filled
REM on the previous iteration) and exit
if %done% GEQ %total% (
for /l %%a in (1,1,%bar.width%) do call set "bar=%bar.char%%%bar%%"
call set /p "out=%%bar%%" <nul
set abort=
goto :EOF
)
REM if the robocopy child process wasn't running on the previous iteration and there
REM are still files left uncopied then we assume that robocopy died unexpectedly
if defined abort goto :EOF
REM check for the robocopy child process (using out "unique" window title)
tasklist /fi "imagename eq robocopy.exe" /fi "windowtitle eq %window.title%" /fo csv /nh 2>nul | findstr "." >nul
REM if it's not found, set a flag (it'll be dealt with on the next interation)
if errorlevel 1 set abort=1 & set loop.delay=1
REM run a duplicate robocopy process with the "/L" switch to so we can extract
REM the total number of files and those that have been copied from the output
for /f "usebackq tokens=3,4,5 delims= " %%a in (`%rc.command% /l /njh /nfl /ndl ^| find "Files"`) do (
set /a total=%%a,remain=%%b,done=%%c
)
REM figure out (roughly) how many files need to be copied to increase the progress
REM bar by one step
set /a bar.step=total / bar.width
REM in case it rounds down to zero...
if %bar.step% EQU 0 set bar.step=1
REM calculate the position using the number of copied files and the step value
set /a bar.position=(done / bar.step)
REM if for some reason the position is greater than the width, fix it
REM (this would occur if the number of files is not much more than
REM the defined bar width)
if %bar.position% GTR %bar.width% set /a bar.position=bar.width
REM draw the bar (we're redrawing the whole thing on each interation)
for /l %%a in (1,1,%bar.position%) do call set "bar=%bar.char%%%bar%%"
set /p "out=%bar%" <nul
title %done% / %total%
REM delay before interating so that the script doesn't thrash the system
ping 127.1 -n %loop.delay% -w 1000 >nul
goto :loop
:::::::::::::::::::::::::::::::::::::::::::::::::::::
----------------------------
20 Jan 2010 15:34
Chimaera
Been trying to get this to work
set "rc=robocopy.exe" << what is this one for plz, is it just for shortnameing the file? or is it like this because you call it with a child
set "rc.command=%rc% "%source%." "%target%." /s" << ive been trying to add my origanal command to here
eg ROBOCOPY %source% %target% %_back_what% %_robo_vista_1% mainly the last bit as i have parameters and exemptions that i need
eg: SET _robo_vista_1=/COPY:DAT /S /B /XJD /XJF /R:0 /W:0 /XA:SH /NJH /NJS /XF %_exc_vista_files% %_exc_prog_files% /XD %target% %_exc_vista_folder% %_exc_prog_folder% %_exc_special_folder%
set "window.title=%rc%_%date%_%time: =0%" <<<this is just for the child window title yes?
With a bit of messing on win7 ive managed to get the windows active but the robocopy window ignores all my exemptions and attributes completely so i guess the set "rc.command=%rc% line isnt working right with my params i even tried adding the /COPY:DAT /S /B /XJ etc etc line instead of the /s part but it ignored that as well.
and the main window with the
START
[ ]
just stays like that with the cursor flashing near it
with this
"%target%." why does it have a full stop at the end of it?, is it needed elsewhere in the file?
Im asuming this will only work with the process in a child window ?
thanks for taking a look
Last edited by Chimaera (20 Jan 2010 15:40)
----------------------------
20 Jan 2010 16:17
bluesxman
Yes.Been trying to get this to work
set "rc=robocopy.exe" << what is this one for plz, is it just for shortnameing the file?
Try this:set "rc.command=%rc% "%source%." "%target%." /s" << ive been trying to add my origanal command to here
eg ROBOCOPY %source% %target% %_back_what% %_robo_vista_1% mainly the last bit as i have parameters and exemptions that i need
eg: SET _robo_vista_1=/COPY:DAT /S /B /XJD /XJF /R:0 /W:0 /XA:SH /NJH /NJS /XF %_exc_vista_files% %_exc_prog_files% /XD %target% %_exc_vista_folder% %_exc_prog_folder% %_exc_special_folder%
Code: Select all
SET _robo_vista_1=/COPY:DAT /S /B /XJD /XJF /R:0 /W:0 /XA:SH /NJH /XF %_exc_vista_files% %_exc_prog_files% /XD %target% %_exc_vista_folder% %_exc_prog_folder% %_exc_special_folder%
set "rc.command=%rc% "%source%." "%target%." "%_back_what%" %_robo_vista_1%"
Yes, so that we can detect if the child process has exited prematurely.set "window.title=%rc%_%date%_%time: =0%" <<<this is just for the child window title yes?
See here."%target%." why does it have a full stop at the end of it?
Correct. CMD doesn't lend itself well to having background processes running in the same window, and "robocopy" must be a background process for the effect you're seeking.Im assuming this will only work with the process in a child window ?
Last edited by bluesxman (20 Jan 2010 16:21)
----------------------------
21 Jan 2010 21:24
bluesxman
I've make a few tweaks:
Now defaults to filling the screen width with the bar (but you can override if you want to).
If there aren't very many files, it will now fill the bar by a more appropriate amount (rather than 1 blob per file)
If 2 blobs per file is too many (bar would fill too early), and 1 blob is too few (bar wouldn't fill fast enough) it'll override the calculated (or forced) bar width to match the number of files, so that 1 blob per file is correct.
I've reworked it slightly so that the total number of files is only calculated once (same idea as the mods I posted earlier, but renders them irrelevant).
Changed the characters used to draw the bar, for no good reason other than aesthetics.
Should behave if there aren't actually any files to copy.
Code: Select all
@echo off
set "source=e:\test\source"
set "target=e:\test\target"
set "rc=robocopy.exe"
set "rc.command=%rc% "%source%." "%target%." /s"
REM make the bar as wide as possible
for /f "usebackq tokens=2" %%a in (`mode con ^| find "Columns:"`) do set /a bar.width=%%a - 3
REM or you can force the width on the next line (no sanity checking is done on this value)
REM set "bar.width=40"
set "bar.char=þ"
set "bar.backchar=ú"
set "bar.size=0"
set "bar.back="
set "bar.del="
set "bar.position=0"
set "bar.position.modifier=0"
set "bar.check=0"
set "loop.delay=3"
set "done=0"
set "total=-1"
set "abort="
set "window.title=%rc%_%date%_%time: =0%"
echo:START
REM spawn the robocopy command with a (hopefully) unique window title that we'll need later
start /min "%window.title%" %rc.command%
REM find the total number of files, so we can shrink the bar to fit the total, if necessary
for /f "usebackq tokens=3,4,5 delims= " %%a in (`%rc.command% /l /njh /nfl /ndl ^| find "Files"`) do (
set /a "total=%%a,done=%%c"
)
set /a "bar.check=bar.width / total" 2>nul
if %bar.check% EQU 1 set /a bar.width=total
REM draw the empty bar
for /l %%a in (1,1,%bar.width%) do (call set "bar.back=%%bar.back%%%bar.backchar%")
call set "bar.del=%%bar.back:%bar.backchar%=%%"
set /p "out=[%bar.back%]%bar.del%" <nul
set /a loop.delay+=1
title Please stand by...
call :loop
echo:
if defined abort (echo:ABORT) ELSE (echo:END)
pause
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::
:loop
:::::::::::::::::::::::::::::::::::::::::::::::::::::
set bar=
REM if all the files have been copied, draw a full bar (in case it didn't get filled
REM on the previous iteration) and exit
if %done% GEQ %total% (
title %done% / %total%
for /l %%a in (1,1,%bar.width%) do call set "bar=%bar.char%%%bar%%"
call set /p "out=%%bar%%" <nul
set abort=
goto :EOF
)
REM if the robocopy child process wasn't running on the previous iteration and there
REM are still files left uncopied then we assume that robocopy died unexpectedly
if defined abort goto :EOF
REM check for the robocopy child process (using out "unique" window title)
tasklist /fi "imagename eq robocopy.exe" /fi "windowtitle eq %window.title%" /fo csv /nh 2>nul | findstr "." >nul
REM if it's not found, set a flag (it'll be dealt with on the next interation)
if errorlevel 1 set abort=1 & set loop.delay=1
REM run a duplicate robocopy process with the "/L" switch to so we can extract
REM the total number of files and those that have been copied from the output
for /f "usebackq tokens=3,4,5 delims= " %%a in (`%rc.command% /l /njh /nfl /ndl ^| find "Files"`) do (
set /a "remain=%%b,done=%%c"
)
REM figure out (roughly) how many files need to be copied to increase the progress
REM bar by one step
set /a bar.step=(total / bar.width) - 1
REM in case its less than one...
if %bar.step% LEQ 0 set bar.step=1
REM calculate the bar modifier, which takes effect if the total number of files
REM is significantly lower than the bar width.
set /a bar.position.modifier=bar.width / total
if %bar.position.modifier% LEQ 0 set /a bar.position.modifier=1
REM calculate the position using the number of copied files and the step value
set /a bar.position=(done / bar.step) * bar.position.modifier
REM if for some reason the position is greater than the width, fix it
REM (this would occur if the number of files is not much more than
REM the defined bar width)
if %bar.position% GTR %bar.width% set /a bar.position=bar.width
REM draw the bar (we're redrawing the whole thing on each interation)
for /l %%a in (1,1,%bar.position%) do call set "bar=%bar.char%%%bar%%"
set /p "out=%bar%" <nul
title %done% / %total%
REM delay before interating so that the script doesn't thrash the system
ping 127.1 -n %loop.delay% -w 1000 >nul
goto :loop
:::::::::::::::::::::::::::::::::::::::::::::::::::::