Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Muhnamana
- Posts: 7
- Joined: 31 May 2011 08:28
#1
Post
by Muhnamana » 07 Jun 2011 09:11
So I stumbled upon the progress bar sample, pretty neat stuff to say the least.
Is there some way to calculate the %max% based on the total lines of code?
Meaning, as an example if you have 2 copy command lines, obviously those 2 lines will be finished before the progress gets to 100%.
Any ideas?
Code: Select all
@ECHO OFF
set "max=11"
call :initProgress %max% "Window Title: [PPP]"
for /l %%N in (1,1,%max%) do (
ping -n 2 -w 1 127.0.0.1>NUL
call:doProgress
)
GOTO:EOF
:initProgress max format -- initialize an internal progress counter and display the progress in percent
:: -- max [in] - progress counter maximum, equal to 100 percent
:: -- format [in,opt] - title string formatter, default is '[P] completed.'
:$created 20060101 :$changed 20080327
:$source http://www.dostips.com
set /a "ProgressCnt=-1"
set /a "ProgressMax=%~1"
set "ProgressFormat=%~2"
if not defined ProgressFormat set "ProgressFormat=[PPPP]"
set "ProgressFormat=%ProgressFormat:[PPPP]=[P] completed.%"
call:doProgress
EXIT /b
:doProgress -- display the next progress tick
:$created 20060101 :$changed 20080327
:$source http://www.dostips.com
set /a "ProgressCnt+=1"
SETLOCAL ENABLEDELAYEDEXPANSION
set /a "per100=100*ProgressCnt/ProgressMax"
set /a "per10=per100/10"
set /a "per10m=10-per100/10-1"
set "P=%per100%%%"
set "PP="
for /l %%N in (0,1,%per10%) do call set "PP=%%PP%%*"
for /l %%N in (%per10%,1,9) do call set "PP=%%PP%% "
set "PPP="
for /l %%N in (0,1,%per10m%) do call set "PPP=%%PPP%%*"
set "ProgressFormat=%ProgressFormat:[P]=!P!%"
set "ProgressFormat=%ProgressFormat:[PP]=!PP!%"
set "ProgressFormat=%ProgressFormat:[PPP]=!PPP!%"
title %ProgressFormat%
EXIT /b
-
Muhnamana
- Posts: 7
- Joined: 31 May 2011 08:28
#2
Post
by Muhnamana » 07 Jun 2011 10:25
Here's an example of what I am using now. I am checking to see if there are any tmp*.pdf files available.
If those files exist, I am echoing the PDF Process Is Running, else I echo that its completed.
I'd like to incorporate the progress into this instead of echoing the status.
Code: Select all
:STATUS
SET TEMPTEST=0
PING 127.0.0.1 -n 100 -w 100> nul
IF EXIST X:\pdf_split\2_page\out\tmp*.pdf SET TEMPTEST=1
IF %TEMPTEST% EQU 1 GOTO RUNNING
IF %TEMPTEST% EQU 0 GOTO FINISHED
:RUNNING
CLS
COLOR 2
ECHO ****************************************
ECHO * *
ECHO * PDF Split process is running! *
ECHO * *
ECHO ****************************************
:LOOP
IF EXIST X:\pdf_split\2_page\out\tmp*.pdf GOTO LOOP
IF NOT EXIST X:\pdf_split\2_page\out\tmp*.pdf GOTO STATUS
:FINISHED
CLS
COLOR 4
ECHO ****************************************
ECHO * *
ECHO * PDF Split process is finished! *
ECHO * *
ECHO ****************************************
PAUSE
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#3
Post
by Ed Dyreen » 10 Jun 2011 07:02
☺
I didn't know we could do that ! Bin looking for this for eons
Code: Select all
for /f %%a in ('copy /Z "%~dpf0" nul') do set "$CR=%%a"
setlocal enabledelayedexpansion
echo.
set /p "=0" <nul
2>&1>nul ping 0.0.0.0
set /p "=!$CR!" <nul
set /p "=1" <nul
2>&1>nul ping 0.0.0.0
set /p "=!$CR!" <nul
set /p "=2" <nul
2>&1>nul ping 0.0.0.0
pause
exit
But I do wonder if it's the fastest way for creating a carriage return
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#4
Post
by jeb » 10 Jun 2011 08:11
This is a really good and fast way to create a single CR.
Introduced by aGerman.
My "old" way was
Code: Select all
::: CR should be used only with DelayedExpansion
:CreateCR
setlocal EnableDelayedExpansion EnableExtensions
set "X=."
for /L %%c in (1,1,13) DO set X=!X:~0,4094!!X:~0,4094!
echo !X! > %temp%\cr.tmp
echo\>> %temp%\cr.tmp
for /f "tokens=2 usebackq" %%a in ("%temp%\cr.tmp") do (
endlocal
set cr=%%a
rem set x=
goto :eof
)
goto :eof
Here I use the buffer overflow of the echo command, normally at the end of an ECHO a CR/LF is appended, but if the line is too long the LF doesn't fit into the buffer, so you can print a (long) line with an CR but without LF.
But the "copy-CR-creation" is much better, it doesn't need a temporary file and it doesn't rely on a buffer overflow.
jeb
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#5
Post
by Ed Dyreen » 10 Jun 2011 08:50
It's not invented by aGerman, I've seen this technique years ago on the net
-
Muhnamana
- Posts: 7
- Joined: 31 May 2011 08:28
#6
Post
by Muhnamana » 10 Jun 2011 11:52
Maybe I'm wrong but what does that have to do with the progress bar?
-
Cleptography
- Posts: 287
- Joined: 16 Mar 2011 19:17
- Location: scriptingpros.com
-
Contact:
#7
Post
by Cleptography » 10 Jun 2011 13:56
@Muhnamana
Pay no attention to Ed, and Jeb they are just mad DOS programmers that started losing their minds and were forced to have to live in caves, watching old reruns of Monty Python and eating Greek yogurt. It's not their faults it is society. No in all seriousness those two are just bots, they were built by Microsoft to interpret questions, and then attempt to give valid responses. Sometimes they work sometimes they don't. J.E.B which stands for Java Enhanced Bots is a 15yr old project divided by pi and E.D. (Egotistical Dumbass) was originally built to take your change on the tollways, but it failed so they gave it to Microsoft.
Code: Select all
@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