中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 16:00
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » The batch code for displaying progress at a high difficulty level is waiting for experts to analyze.
Printable Version  4,940 / 19
Floor1 jellord Posted 2007-03-18 12:21
初级用户 Posts 26 Credits 92
@echo off
:: Simulate progress, with display of remaining time, completed progress, and progress bar
:: code by bg 2006-10-8 CMD@XP
color 1f
title.
mode con lines=10
rem Progress bar ▉▉▉▉▉
set work=0
set n=0
set mo=0
set number=0
rem all is the total number
set all=60
set time=%all%
:show

:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check

:2

cls
echo Progress: %n% / %all% Remaining time:%time% seconds
echo.
echo.
echo Completed %work% %%%
echo.
if not "%num%"=="" echo %num%
if not "%num%"=="" echo %num%

if %work%==100 goto end

ping 127.1 -n 1 >nul
set /a n=%n%+1
set /a time=%all%-%n%
set /a work=(%n%)*100/(%all%)
set /a number=%work%/3
set /a number=%number%+1
goto show
endlocal

:end
endlocal
pause>nul

Please help me analyze the thinking of this batch processing. I really can't understand it. There is no content in the show tag and 2 tag above. Why? The check tag is not seen being referenced in the subsequent code. Then how can it be executed? Please help me analyze, thank you thank you!!!
Floor2 zh159 Posted 2007-03-18 12:34
金牌会员 Posts 1,467 Credits 3,687
:
:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check

If %number% is greater than %mo%, it will execute set num=%num%▉&set /a mo=%mo%+1&goto check and return to :check; if less, it will go directly to the next step

[ Last edited by zh159 on 2007-3-18 at 12:04 AM ]
Floor3 zhoushijay Posted 2007-03-18 13:02
高级用户 Posts 375 Credits 845
```batch
@echo off

color 1f \\Set background color
title. \\Title:
mode con lines=10 \\Window size
rem Progress bar ▉▉▉▉▉ \\Comment, multiple commands have no effect
set work=0
set n=0
set mo=0
set number=0 \\Here are a series of variables set
rem all is the total number
set all=60
set time=%all%
:show

:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check \\If %number% is greater than %mo%, set variable num=%num%▉(Note here, because the value of variable num is =%num%▉, so the value of num will become =%num%▉▉ the second time it loops here, and =%num%▉▉▉ the third time)
:2

cls
echo Progress: %n% / %all% Remaining time:%time% seconds \\The displayed progress, because there is set /a n=%n%+1 below, so the value of n is 2 the second time it loops here, 3 the third time, so there will be the effect of 1/60 2/60 3/60
echo.
echo.
echo Completed %work% %%% \\The same principle as Progress: %n%/%all%
echo.
if not "%num%"=="" echo %num% \\The effect of the above num=%num%▉▉▉ will be displayed here
if not "%num%"=="" echo %num% \\The same as above

if %work%==100 goto end Before the value of %work% reaches 100, it will keep returning to the above to execute again

ping 127.1 -n 1 >nu Pause for 1 second
set /a n=%n%+1 \\Progress: %n% / %all% The value of %n% is +1 here every time
set /a time=%all%-%n% \\The value of %time% will change here every time
set /a work=(%n%)*100/(%all%) Convert the value of %work% to % form
set /a number=%work%/3
set /a number=%number%+1 \\This command cooperates with the above command to make the value of %number% greater than the value of %mo%
So as to meet the conditions to execute the statement under :check
goto show \\Return to :show, when the above conditions are not met, it will reach here,
endlocal \\This command will localize the above environment, and the original system environment will not be restored. It is estimated that the author wants to play a prank. It is recommended to delete it during testing

:end
```
Floor4 jellord Posted 2007-03-19 02:52
初级用户 Posts 26 Credits 92
Thank you so much to the person above, but there is still a small problem:
Is the code after the first tag in the code executed directly? Is the first tag not skipped? Otherwise, all subsequent code will be skipped. I don't know if that's the case?
Floor5 xycoordinate Posted 2007-03-19 03:24
中级用户 Posts 228 Credits 493 From 安徽
How to combine it with a program that "needs to display progress"?
Floor6 axi Posted 2007-03-20 01:30
中级用户 Posts 93 Credits 238 From GZ
Originally posted by xycoordinate at 2007-3-18 02:24 PM:
How to combine it with a program that "needs to display progress"???



By the way, it's only useful if it can be combined with the program that's being installed.
Floor7 zhoushijay Posted 2007-03-22 00:17
高级用户 Posts 375 Credits 845
The first tag will not run the first time because the if condition is not satisfied the first time.

Regarding how to embed the operation, when I saw this post, I had some inspiration. It should be not difficult to implement. I will post it when I have time. Let me talk about the idea here first, and everyone can also study it together.

For example, when copying, continuously dir that file, extract the digital value of the file size and put it into the progress: %n% / %all%, so as to control whether the condition is satisfied.
Floor8 zh159 Posted 2007-03-22 00:44
金牌会员 Posts 1,467 Credits 3,687
Just think about it:
For example, how do you determine that the file has been copied 1/10?!!
How to pause the copy when it's copied 1/10 and jump back to display the progress bar?!!
How to jump back to the copy point after part of the progress bar is displayed?!!

PS: Don't say you use rar to compress into 10 volumes, then copy each volume one by one, and then decompress

copy does have a /z parameter to display the percentage of copy progress
Floor9 zhoushijay Posted 2007-03-22 02:57
高级用户 Posts 375 Credits 845
You can use the shart command to re - pop up a window to display the process. Pass the total size of the file to %all% and pass the copied number to %n%. Now the main problem is not knowing whether the dir command can detect the actual size of an unfinished copied file.
Floor10 zh159 Posted 2007-03-22 04:09
金牌会员 Posts 1,467 Credits 3,687
Tried it, and during the copying process, it showed that the file size is the same as the original.
Floor11 axi Posted 2007-03-22 05:03
中级用户 Posts 93 Credits 238 From GZ
Originally posted by zh159 at 2007-3-21 11:44:
You can just imagine:
For example, how do you determine that a file has been copied 1/10?!!
How to pause the copy after copying 1/10 and jump back to display the progress bar?!!
How to jump back to the copy point after part of the progress bar is displayed?!!

PS: Don't say you use rar to compress into 10 volumes, then copy each volume one by one, and then decompress

copy does have a /z parameter to display the percentage of copy progress



Oh, the copy has this useful parameter! May I ask how to extract the progress percentage obtained from copy /z and transfer it to the progress bar?

[ Last edited by axi on 2007-3-21 at 04:09 PM ]
Floor12 zh159 Posted 2007-03-22 05:48
金牌会员 Posts 1,467 Credits 3,687
This parameter's display is from copy itself. If you really want to extract this progress percentage, it is suggested:
1. Find a software expert
2. Find Microsoft

PS: Batch processing is a single-threaded execution method, and each batch processing can only execute one command at a time
Floor13 jackyggt Posted 2007-03-30 13:27
初级用户 Posts 38 Credits 76
Bump
Floor14 flyinspace Posted 2007-03-30 13:38
银牌会员 Posts 517 Credits 1,206
Oh?
I do have an idea.
Just don't write the remaining time.
Floor15 bg Posted 2007-04-05 18:51
初级用户 Posts 34 Credits 118
This batch script is written by me. I didn't send it out. How does the thread starter have it??????!!!!!
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023