|
jellord
初级用户
 
积分 92
发帖 26
注册 2007-3-10
状态 离线
|
『楼 主』:
高难度的显示进度的批处理代码有待高人分析
使用 LLM 解释/回答一下
@echo off
:: 模拟进度,有剩余时间、已完成进度、进度条的显示
:: code by bg 2006-10-8 CMD@XP
color 1f
title.
mode con lines=10
rem 进度条 ▉▉▉▉▉
set work=0
set n=0
set mo=0
set number=0
rem all是总数
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 进度: %n% / %all% 剩余时间:%time%秒
echo.
echo.
echo 完成 %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
请大家帮我分析一下该批处理的思路,实在看不懂,上面的show标签和2标签都没内容啊,为什么呢?check标签在后面的代码中也没看到被引用,那它怎么会被执行呢?请大家帮我分析一下,多谢多谢了!!!
@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!!!
|
|
2007-3-18 12:21 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check
%number%大于%mo%就会执行set num=%num%▉&set /a mo=%mo%+1&goto check并返回:check,小于则直接到下一步
Last edited by zh159 on 2007-3-18 at 12:04 AM ]
:
: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 ]
|
|
2007-3-18 12:34 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
color 1f \\设置背景颜色
title. \\标题:
mode con lines=10 \\窗口大小
rem 进度条 ▉▉▉▉▉ \\注释,多命令无作用
set work=0
set n=0
set mo=0
set number=0 \\此处为设置一系列变量
rem all是总数
set all=60
set time=%all%
:show
:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check \\如果%number% 大于 %mo% 则设置变量num=%num%▉(注意这里,因为变量num的值为=%num%▉ 所以到第二次循环到这里是后num的值就会变成=%num%▉▉ 第3次为=%num%▉▉▉ )
:2
cls
echo 进度: %n% / %all% 剩余时间:%time%秒 \\显示的进度,由于下面有set /a n=%n%+1 所以第2次循环到这里n的值为 2,第3次为3 因此就会有 1/60 2/60 3/60 的效果
echo.
echo.
echo 完成 %work% %%% \\与 进度: %n%/%all% 原理相同
echo.
if not "%num%"=="" echo %num% \\上面的 num=%num%▉▉▉ 效果将在这里显示
if not "%num%"=="" echo %num% \\上同
if %work%==100 goto end 在%work%值没到100之前将不断回到上面重新执行
ping 127.1 -n 1 >nu 停顿1秒l
set /a n=%n%+1 \\进度: %n% / %all% %n%的值就是每次在这里+1
set /a time=%all%-%n% \\%time%的值将每次在这里改变
set /a work=(%n%)*100/(%all%) 将%work%的值换算成%形式
set /a number=%work%/3
set /a number=%number%+1 \\此命令配合上一行命令将使%number%值 大于%mo%值
从而满足条件执行:check下的语句
goto show \\返回:show处,上面条件不满足时将会到达此处,
endlocal \\此命令将是以上环境本地化,原来系统的环境将无法还原,估计是作者想搞恶作剧,建议测试的时候删除
:end
```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
```
|
|
2007-3-18 13:02 |
|
|
jellord
初级用户
 
积分 92
发帖 26
注册 2007-3-10
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
太感谢楼上了,不过还有一点小问题:
在代码中的第一个标签后面的代码是直接执行的吗?没有跳过第一个标签吧,否则后面所有的代码都会被跳过的,不知道是不是这样的?
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?
|
|
2007-3-19 02:52 |
|
|
xycoordinate
中级用户
  
积分 493
发帖 228
注册 2007-2-16 来自 安徽
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
如何将它与"需要显示进度"的程序结合呢???
How to combine it with a program that "needs to display progress"?
|
|
2007-3-19 03:24 |
|
|
axi
中级用户
   脚本爱好者
积分 238
发帖 93
注册 2007-3-11 来自 GZ
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by xycoordinate at 2007-3-18 02:24 PM:
如何将它与"需要显示进度"的程序结合呢???
对了,能与正在安装的程序结合才有用呀。
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.
|
|
2007-3-20 01:30 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
第一个标签第一次是不会运行的,因为 if 条件在第一次的时候不满足
关于如何嵌入操作中,本人看到这个帖子的时候有了点灵感,应该不难实现,等有空的时候发个上来,先在这里说下思路,大家也可以一起来研究研究。
比如copy的时候,不断 dir 那个文件,把文件大小的数字提取出来放入 进度: %n% / %all%,以次来控制他的条件是否满足
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.
|
|
2007-3-22 00:17 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
想想都知道:
比如你如何确定文件复制了1/10?!
如何复制了1/10暂停复制跳回显示进度条?!
进度条部分显示后如何跳回复制点?!
PS:别说你用rar分10卷压缩,然后一卷卷复制,再解压缩
copy倒是有个/z参数来显示复制进步百分比
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
|
|
2007-3-22 00:44 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
可以用shart命令重新跳出一个窗口来显示进程 将文件总大小传给%all%,将已复制的数字传给%n%,
现在主要的问题是不知道dir命令能否检测出一个未复制完的文件的实际大小
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.
|
|
2007-3-22 02:57 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
试过了,复制过程中显示文件的大小和原来的一样
Tried it, and during the copying process, it showed that the file size is the same as the original.
|
|
2007-3-22 04:09 |
|
|
axi
中级用户
   脚本爱好者
积分 238
发帖 93
注册 2007-3-11 来自 GZ
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by zh159 at 2007-3-21 11:44:
想想都知道:
比如你如何确定文件复制了1/10?!
如何复制了1/10暂停复制跳回显示进度条?!
进度条部分显示后如何跳回复制点?!
PS:别说你用rar分10卷压缩,然后一卷卷复制,再解压缩
copy倒是有个/z参数来显示复制进步百分比
原来 copy 有这个好用参数!请问如何提取这个由 copy /z 所得的进度百分比,并转到进度条中呢?
Last edited by axi on 2007-3-21 at 04:09 PM ]
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 ]
|
|
2007-3-22 05:03 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
这个参数的显示是copy自带的,如果你真想提取这个进度百分比,建议:
1、找软件高手
2、找微软
PS:批处理是单线程执行方式,每个批处理每次只能执行一个命令
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
|
|
2007-3-22 05:48 |
|
|
jackyggt
初级用户
 
积分 76
发帖 38
注册 2007-3-13
状态 离线
|
|
2007-3-30 13:27 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
哦?
我倒有一个想法。
不写剩余时间就可以了。
Oh?
I do have an idea.
Just don't write the remaining time.
|
|
2007-3-30 13:38 |
|
|
bg
初级用户
 
积分 118
发帖 34
注册 2006-1-10
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
这个批处理是我写的,我没有发出去,楼主怎么有??????!!!!!!
This batch script is written by me. I didn't send it out. How does the thread starter have it??????!!!!!
|
|
2007-4-5 18:51 |
|