You are not logged in.
Hi
Im messing with this atm that i found on the net
@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 > nulgoto :EOF
:EXIT
title FIN!
endlocal
what im trying to make is a progress indicator for a robocopy in total so as the job starts it will be 0%-100%, or * to ********** etc etc
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
Last edited by Chimaera (19 Jan 2010 09:23)
Offline
Ok i came up with this its a bit rough but seems to work
@echo off
setlocalset COUNT=0
set MAXCOUNT=1
set SECONDS=2set _indicator1=*
set _indicator2=**
set _indicator3=***
set _indicator4=****
set _indicator5=*****
set _indicator6=******
set _indicator7=*******
set _indicator8=********
set _indicator9=*********
set _indicator10=**********
set _indicator11=***********
set _indicator12=************
set _indicator13=*************
set _indicator14=**************
set _indicator15=***************:start
echo.
echo.
echo %_indicator1%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator2%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator3%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator4%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator5%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator6%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator7%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator8%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator9%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator10%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator11%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator12%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator13%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator14%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
echo.
echo.
echo %_indicator15%
ping -n %SECONDS% 127.0.0.1 > nul
ping -n %SECONDS% 127.0.0.1 > nul
CLS
if /i "%COUNT%" equ "%MAXCOUNT%" goto :stop
set /a count+=1goto :start
:stop
Last edited by Chimaera (19 Jan 2010 20:09)
Offline
Maybe this will help...
Offline
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).
@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
:::::::::::::::::::::::::::::::::::::::::::::::::::::
Last edited by bluesxman (20 Jan 2010 00:50)
cmd | *sh | ruby | chef
Offline
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)
Offline
Been trying to get this to work
set "rc=robocopy.exe" << what is this one for plz, is it just for shortnameing the file?
Yes.
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%
Try this:
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%"
NB -- I've removed the "/NJS" switch and you must leave it off as "%rc.command%" is reused to check the current status and the job summary information is essential for that to work -- most probably this is why your status bar didn't work.
set "window.title=%rc%_%date%_%time: =0%" <<<this is just for the child window title yes?
Yes, so that we can detect if the child process has exited prematurely.
"%target%." why does it have a full stop at the end of it?
See here.
Im asuming this will only work with the process in a child window ?
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.
Last edited by bluesxman (20 Jan 2010 16:21)
cmd | *sh | ruby | chef
Offline
Ok now we are getting somewhere
couple of unusual things that occured i thought i would mention
The administrator window {parent} got to 1 short of the end like this
START
[******************* ]
and on the title it says 4441 / 4474 so 33 short and it stayed open, the child closed at the end of the robo run.
should it have finished completly? , i remember you mentioned the accuracy
and for some odd reason i got two copys of the backup, one which i couldnt open which gave drive unavailable errors and the other one worked as normal.
I guess the only one i need is the normal one but which is which who knows lol
Weird the odd one i cant delete off the desktop, ill have to try safe mode
i understand better about the full stop now, so really i should add the full stop to all my %????% params y?
outstanding bit of work m8 :clap: :clap:
Last edited by Chimaera (20 Jan 2010 21:53)
Offline
and on the title it says 4441 / 4474 so 33 short and it stayed open, the child closed at the end of the robo run.
should it have finished completly? , i remember you mentioned the accuracy
I'm going to guess that this is due to files appearing at the source location (see the "notes" section in my original post.)
Here's a mod that might help (two areas of code to hack):
set "done=0"
set "total=1"
set "get.total=1"
set "abort="
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 (
if defined get.total (set /a total=%%a&set get.total=)
set /a remain=%%b,done=%%c
)
and for some odd reason i got two copys of the backup, one which i couldnt open which gave drive unavailable errors and the other one worked as normal.
I guess the only one i need is the normal one but which is which who knows lol
Weird the odd one i cant delete off the desktop, ill have to try safe mode
Don't know what to tell you on that one.
so really i should add the full stop to all my %????% params
For source and target, yeah.
cmd | *sh | ruby | chef
Offline
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.
@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
:::::::::::::::::::::::::::::::::::::::::::::::::::::
Last edited by bluesxman (21 Jan 2010 23:04)
cmd | *sh | ruby | chef
Offline
Ive worked out what the folder appears from it first appears when you try and delete the file after the test
"Test" becomes "Test." for some strange reason and its like the folder dosent exist like an echo after deleting and it takes a lot of messing about to get rid off it, now i dont know if this is a windows 7 issue or not?
ill try the new batch in a bit when i get time and let you know what happens
usually at the end of the batch i run
ATTRIB /S /D -r -a -s -h "%target%."
ATTRIB /S /D -r -a -s -h "%target%.\*.*"
problem is where do i put this on the batch so its the last thing before closing the file so it does the robocopy the sets the attribs so all the files are workable as their is hidden and all sorts of stuff involved.
Does it need to be in the loop section or somewhere else?
Edit
just ran the file and i get this
START
[Divide by zero error.························································]
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Divide by zero error.
Managed to capture a bit of the output
Last edited by Chimaera (11 Feb 2010 19:52)
Offline
Did you read my last two posts?!
EDIT: Sorry, I think you might have caught a version that had a bug in it -- I edited the tweaked script posted later on yesterday evening. Please have another go with the version that's there now.
Last edited by bluesxman (22 Jan 2010 15:45)
cmd | *sh | ruby | chef
Offline
Not quite sure whats happening now, i see this straight away and the title of the parent window reads
Administrator : 0 / -1
no matter what the child window is doing
START
[■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]
END
Press any key to continue . . .
The child window seems to be running as normal
any thoughts
Last edited by Chimaera (22 Jan 2010 19:40)
Offline
Yes, I'll wager you are still including /NJS in your robocopy command. See comments regarding this in post #6.
cmd | *sh | ruby | chef
Offline
As always ur the man lol
with the messing about copying bits from my script to yours i had copied the /NJS again thx again
now this time
Title gets to 2689 / 2714
and the bar look pretty much full
START
[■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]
but it just stops there.. it never gets to show END
so im guessing it never gets to this statement somehow
if defined abort (echo:ABORT) ELSE (echo:END)
i tried my attrib section above and below the loop section but it dosent perform it so the files are still hidden possible because the END dosent happen
goto :loop
::::::::::::::::::::::::::::::::::::::::::::::::::::::attrib
::
ATTRIB /S /D -r -a -s -h %target%
ATTRIB /S /D -r -a -s -h %target%\*.*
Last edited by Chimaera (23 Jan 2010 00:11)
Offline
I've tested it with various numbers of files (0, 1, 5, 40, 70, 2000 and 33,000) and it seems to work fine (though this was static test data).
Perhaps files at the source location are changing or are locked for reading by some other process and that is causing a discrepancy so that the value for %total% never gets reached. Given that it looks like you're trying to copy the whole of C: (with some exceptions) I'm not particularly surprised about this.
However, it should at least "ABORT" once it detects that the child process has disappeared.
Does the child process actually close when it's done?
What happens if you close the child process manually, part way through the copy?
Speculating that the tasklist command under Vista/Win7 behaves in a different manner to WinXP, perhaps this hack will make a difference:
tasklist /fi "imagename eq robocopy.exe" /fi "windowtitle eq %window.title%" /fo csv /nh 2>nul | find /i "robocopy.exe" >nul
As for your "ATTRIB" commands, you'd need to place them here:
if defined abort (echo:ABORT) ELSE (echo:END)
ATTRIB /S /D -r -a -s -h %target%
ATTRIB /S /D -r -a -s -h %target%\*.*
pause
goto :EOF
But if you're not getting an "END" or "ABORT" message they'll never get run.
Last edited by bluesxman (23 Jan 2010 16:21)
cmd | *sh | ruby | chef
Offline
That seems to have done the job m8
It stopped with a Abort
2703 / 2710
i guess the missing files are the running windows processes, even though robocopy discounts them, it still counts them causing the variable
START
[■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■]
ABORT
Press any key to continue . . .
I keep forgetting win7 is a tad different, than xp
Thanks for joining in and helping out m8
Last edited by Chimaera (23 Jan 2010 20:37)
Offline
Finally got round to doing some work with this and got a fair way but i have run into a few questions
Problem appears to be im running 3 versions of this one under another
for eg:
Main Backup
Outlook Backup
Firefox Backup
but the first section works properly and follows the exemptions as it supposed to, but the second 2 section just ignore the presets that i have set for it/
i have tried moving stuff around just in case it needs it later in the file for eg and ive tried diff permutations.
i start each section with the robo line so it dosent confuse the others for eg
SET "rc.command=%rc% "%source%." "%target%." "%_back_what%" %_robo_vista_1%"
rest of stuff to
goto :loop
:::::::::::::::::::::::::::::::::::::::::::::::::::::
SET "rc.command=%rc% "%source%." "%target%." "%_back_outlook%" %_robo_outlook_1%"
and same again for the last one.
I wondered if its remembering some of the previous settings from doing the loops before and its confusing it
the progress line shows each time and the robocopy window is there its just not picking up files
is there a way of clearing settings out of memory so i can test?
Offline
Can't easily troubleshoot a script I can't see. Can you post it? Just the script -- don't need to see the output at this time.
cmd | *sh | ruby | chef
Offline
Ive bolded the stuff ive changed and the first one uses
set _back_what=*.*
and the second uses
SET _back_outlook=*.pst *.email *.wab *.imapmbox *.sdm *.sig *.dbx *.eml *.maildb *.mailhost *.boe *.box *.dic *.emlx *.mai *.mbg *.mbox *.mbs *.mbx *.toc *.fol nndbase.* *.msf *.msg *.nws *.oab *.obi *.oft *.ost *.pab *.pmi *.pmm *.vfb *.iaf *.nk2
::
:_vista_start
::
SET "rc.command=%rc% "%source%." "%target%." "%_back_what%" %_robo_vista_1%"echo Starting Main Backup ...... Please Wait
::
for /f "usebackq tokens=2" %%a in (`mode con ^| find "Columns:"`) do set /a bar.width=%%a - 3
::
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
echo.
start /min "%window.title%" %rc.command%
::
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
::
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:
echo.
::
if defined abort (echo:ABORT) ELSE (echo:END)
::
goto :vista_outlook
::
pause
::
:loop
::
set bar=
::
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
)
::
if defined abort goto :EOF
::
tasklist /fi "imagename eq robocopy.exe" /fi "windowtitle eq %window.title%" /fo csv /nh 2>nul | find /i "robocopy.exe" >nul
::
if errorlevel 1 set abort=1 & set loop.delay=1
::
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"
)
::
set /a bar.step=(total / bar.width) - 1
::
if %bar.step% LEQ 0 set bar.step=1
::
set /a bar.position.modifier=bar.width / total
if %bar.position.modifier% LEQ 0 set /a bar.position.modifier=1
::
set /a bar.position=(done / bar.step) * bar.position.modifier
::
if %bar.position% GTR %bar.width% set /a bar.position=bar.width
::
for /l %%a in (1,1,%bar.position%) do call set "bar=%bar.char%%%bar%%"
::
set /p "out=%bar%" <nul
::
title %done% / %total%
::
ping 127.1 -n %loop.delay% -w 1000 >nul
::
goto :loop
:: ==========================================================
:vista_outlook
::
SET "rc.command=%rc% "%source%." "%target%." "%_back_outlook%" %_robo_outlook_1%"
::
echo Starting Outlook Backup ...... Please Wait
::
for /f "usebackq tokens=2" %%a in (`mode con ^| find "Columns:"`) do set /a bar.width=%%a - 3
::
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
echo.
start /min "%window.title%" %rc.command%
::
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
::
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:
echo.
::
if defined abort (echo:ABORT) ELSE (echo:END)
::
goto :vista_firefox
::
:loop
::
set bar=
::
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
)
::
if defined abort goto :EOF
::
tasklist /fi "imagename eq robocopy.exe" /fi "windowtitle eq %window.title%" /fo csv /nh 2>nul | find /i "robocopy.exe" >nul
::
if errorlevel 1 set abort=1 & set loop.delay=1
::
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"
)
::
set /a bar.step=(total / bar.width) - 1
::
if %bar.step% LEQ 0 set bar.step=1
::
set /a bar.position.modifier=bar.width / total
if %bar.position.modifier% LEQ 0 set /a bar.position.modifier=1
::
set /a bar.position=(done / bar.step) * bar.position.modifier
::
if %bar.position% GTR %bar.width% set /a bar.position=bar.width
::
for /l %%a in (1,1,%bar.position%) do call set "bar=%bar.char%%%bar%%"
::
set /p "out=%bar%" <nul
::
title %done% / %total%
::
ping 127.1 -n %loop.delay% -w 1000 >nul
::
goto :loop
:: ==========================================================
:vista_firefox
its basically ur script with a few direction changes
first section works fine second one igores the preset filetypes
Last edited by Chimaera (24 Mar 2010 09:02)
Offline
No offense but that's a right old mess. You ought to be doing something along these lines (based on my original rather than your version):
@echo off
set "rc=robocopy.exe"
set "source=e:\test\source1"
set "target=e:\test\target1"
call :main_body "Backup 1"
set "source=e:\test\source2"
set "target=e:\test\target2"
call :main_body "Backup 2"
set "source=e:\test\source3"
set "target=e:\test\target3"
call :main_body "Backup 3"
pause
goto :EOF
:main_body
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% %~1"
echo:START %~1
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 %~1) ELSE (echo:END %~1)
REM 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
:::::::::::::::::::::::::::::::::::::::::::::::::::::
Last edited by bluesxman (24 Mar 2010 18:41)
cmd | *sh | ruby | chef
Offline
to bluesxman
thanx so much.... but ur script 200MB over file not check progress bar...
how solve it?
pls reply me....
Offline
Sorry but I don't understand the question.
cmd | *sh | ruby | chef
Offline
bluesxman: Thanks for your script it is exactly what I've been looking for...but....when I run the script the bar (bar.width=50) looks OK but once the script starts to redraw the bar the bar.char is written behind the bar it self like this:
START SiteComputer 1
[··················································]*****************************************************************************************************************************
and it just continues to expand outside the bar.width and wraps to the next row until it's done with the copy....
I've also noticed that if the copy already exists (100% done) the bar.chars will be equal to the bar.width (50) but it will still be printed as
START SiteComputer 1
[··················································]**************************************************
END
I've done some adaptations to the script but that should not have anything to do with the messed up printout since I get the same "error" using your original script
Any ideas why?
Offline
Mine has changed as well from the original that i had, i managed to get mine working again by adding an extra character which the forum seems to be blocking, i think when the forum changed it stops the character which is a square with little numbers
inside it, i dont know what the char is actually called
you need to add one after the red character and one either side of the second one
call set "bar.del=%%bar.back:%bar.backchar%=%%"
And
for /l %%a in (1,1,%bar.position%) do call set "bar=%bar.char%%%bar%%"
It seems to need the extra characters to work right
Hope this works for you
@Simon Can you have a look at why the forum is blocking the special Character please as i pasted it in the post but as soon as i submitted it it wiped it from the text
Last edited by Chimaera (08 Sep 2010 10:25)
Offline
Ah yes, I think the new version of the forum is blocking the "backspace" character than is used heavily.
cmd | *sh | ruby | chef
Offline
Thanks Chimaera it got better but not perfect
I still get the faulty position of the output
START SiteComputer 1
[--------------------------------------------------]***************
And when the rc is running the amount of "*" is incorrectly printed. The rc contains of ~3500 files, when almost all files have been copied the amount of written "*" was only 15 (bar.width=50). Once the copy was done the script did a M$-jump and printed out the remaining 35 "*"
START SiteComputer 1
[--------------------------------------------------]**************************************************
END
I know it's not easy to troubleshoot a script without seeing it so here goes:
@echo off
title Please stand by....
rem net use p: /delete /y
net use q: /delete /y
net use \\192.168.0.20\c$ /delete /y
net use \\192.168.0.21\c$ /delete /y
net use \\192.168.0.22\c$ /delete /y
net use \\192.168.0.23\c$ /delete /y
net use \\192.168.0.24\c$ /delete /y
cls
rem net use p: /USER:rc \\192.168.0.6\c$
for /f "delims=" %%a in (
'dir "P:\TestProcessed\*.*" /b /od'
) do set "dir=%%a"
setlocal
setlocal enabledelayedexpansion
set x-factor=100000000000
set num1=%dir%
set num2=%x-factor%
echo "%dir%">len1.tmp
echo "%x-factor%">len2.tmp
call :getlen len1.tmp len2.tmp
if %len1% equ %len2% (
set /a len = len1
call :COMPARE
) else (
if %len1% gtr %len2% (
set /a len = len1
set /a dif = len1 - len2
) else (
set /a len = len2
set /a dif = len2 - len1
set tmp=%num1%
set num1=%num2%
set num2=!tmp!
)
for /l %%a in (1,1,!dif!) do set num2=0!num2!
)
set /a len-=1
set carry=0
for /l %%a in (!len!,-1, 0) do (
set /a digit = !num1:~%%a,1! + !num2:~%%a,1! + !carry!
if !digit! geq 10 (
set /a carry = 1
set /a digit = !digit! %% 10
) else (
set carry = 0
)
set sum=!digit!!sum!
)
if %carry% equ 1 set sum=1%sum%
set new_dir=%sum%
goto CD-COPY
:COMPARE
set flag=
for /l %%a in (0,1,!len!) do (
if not defined flag (
set i=%%a
if %num1:~%%a,1% gtr %num2:~%%a,1% (
set flag=1
) else (
if %num2:~%%a,1% gtr %num1:~%%a,1% (
set flag=1
set tmp=!num1!
set num1=!num2!
set num2=!tmp!
)
)
)
)
exit /b
:GETLEN
set /a %~n1 = %~z1 - 4
set /a %~n2 = %~z2 - 4
del %1 %2
exit /b
:CD-COPY
net use q: /USER:rc \\192.168.0.20\c$
set "rc=robocopy.exe"
set "source=P:\TestProcessed\%dir%"
set "target=q:\temp\test\"
cls
call :main_body "SiteComputer 1"
title Please stand by....
net use q: /delete /y
net use q: /USER:rc \\192.168.0.21\c$
cls
call :main_body "SiteComputer 2"
title Please stand by....
net use q: /delete /y
net use q: /USER:rc \\192.168.0.22\c$
cls
call :main_body "SiteComputer 3"
title Please stand by....
net use q: /delete /y
net use q: /USER:rc \\192.168.0.23\c$
cls
call :main_body "SiteComputer 4"
title Please stand by....
net use q: /delete /y
net use q: /USER:rc \\192.168.0.24\c$
cls
call :main_body "SiteComputer 5"
goto :EOF
:MAIN_BODY
set "rc.command=%rc% /E /NP /TEE %source% %target%"
REM make the bar as wide as possible
rem for /f "usebackq tokens=2" %%a in (`mode con ^| find "Columns:"`) do set /a bar.width=%%a - 3
set "bar.width=50"
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% %~1"
echo:START %~1
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 %~1) ELSE (echo:END %~1)
timeout 60
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 CD transfer in progress....Copying file %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 CD transfer in progress....Copying file %done% / %total%
timeout 5 >nul
rem ping 127.1 -n %loop.delay% -w 1000 >nul
goto :LOOP
:EOF
net use q: /DELETE /Y
rem net use p: /DELETE /Y
Thanks in advance!
Offline
mine works fine here now Ive added the extra character
i did notice however that it dosen't work when i define the length of the progress bar for some reason.
have you tried define the window instead and let the bar run as normal?
And bear in mind as bluesxman says earlier in the thread this is not an exact science due to windows files it cannot access etc so it may not report correctly
Last edited by Chimaera (09 Sep 2010 20:06)
Offline
hi guys.. need some help with this script ...
Everything works fine .. adapted the script to my stuff but have one tiny tiny problem ..
As mention above the bar is drawn like this [---------------------------]*******************
And for the love of god everyone is talking about the missing character ... but i do not understand it what backspace character are u talking about ... "square with small numbers in it ?" Ithere isn't that character on the ascii table ...
Can anyone upload de bat file somewhere so i can download it and see ...
Thanks in advance !
Offline
Helo guys.
Old post but can you please explain how to put the backspace character inside the script? Thanks
Offline
Helo guys.
Old post but can you please explain how to put the backspace character inside the script? Thanks
You probably noticed that the post above yours has the same problem. This is because at some point, the forum software removed the backspace characters.
Originally, the code above had an actual backspace character (ASCII value 8) at the end of one of the set lines (I'm not sure which one, and I don't care since there are better ways to get a backspace character that I'm about to mention). If you absolutely insist on setting a backspace character this way, you can open a text editor that's more advanced than regular Notepad (I'm using Notepad++ but Ultraedit should work as well), hold ALT, and press 008 on the keypad. Since this method is clearly not useful for posting code online, I recommend not doing this.
A better way to generate a backspace character is to take advantage of the prompt command.
for /F %%A in ('echo prompt $H ^| cmd') do set "BS=%%A"
The $H option of prompt generates a backspace, which can then be piped to a new instance of cmd.exe and stored in the variable %BS%.
Offline