China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 06:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » The batch code for displaying progress at a high difficulty level is waiting for experts to analyze. View 4,757 Replies 19
Original Poster Posted 2007-03-18 12:21 ·  中国 福建 福州 电信
初级用户
Credits 92
Posts 26
Joined 2007-03-10 07:44
19-year member
UID 81291
Gender Male
Status Offline
@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!!!
Floor 2 Posted 2007-03-18 12:34 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
:
: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 ]
Floor 3 Posted 2007-03-18 13:02 ·  中国 浙江 绍兴 诸暨市 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
```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
```
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
jellord +2 2007-03-19 02:52
tashaxin +2 2007-03-30 23:39
Floor 4 Posted 2007-03-19 02:52 ·  中国 福建 福州 电信
初级用户
Credits 92
Posts 26
Joined 2007-03-10 07:44
19-year member
UID 81291
Gender Male
Status Offline
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?
Floor 5 Posted 2007-03-19 03:24 ·  中国 安徽 马鞍山 电信
中级用户
★★
Credits 493
Posts 228
Joined 2007-02-16 00:38
19-year member
UID 79596
Gender Male
From 安徽
Status Offline
How to combine it with a program that "needs to display progress"?
Floor 6 Posted 2007-03-20 01:30 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
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.
Floor 7 Posted 2007-03-22 00:17 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
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.
Floor 8 Posted 2007-03-22 00:44 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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
Floor 9 Posted 2007-03-22 02:57 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
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.
Floor 10 Posted 2007-03-22 04:09 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Tried it, and during the copying process, it showed that the file size is the same as the original.
Floor 11 Posted 2007-03-22 05:03 ·  中国 广东 广州 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
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 ]
Floor 12 Posted 2007-03-22 05:48 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
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
Floor 13 Posted 2007-03-30 13:27 ·  中国 湖北 武汉 电信
初级用户
Credits 76
Posts 38
Joined 2007-03-13 02:54
19-year member
UID 81544
Gender Male
Status Offline
Bump
Floor 14 Posted 2007-03-30 13:38 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Oh?
I do have an idea.
Just don't write the remaining time.
Floor 15 Posted 2007-04-05 18:51 ·  中国 湖北 武汉 电信
初级用户
Credits 118
Posts 34
Joined 2006-01-10 09:01
20-year member
UID 48727
Status Offline
This batch script is written by me. I didn't send it out. How does the thread starter have it??????!!!!!
Forum Jump: