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-08-11 05:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Discussion] Issues with Practicalizing Progress Bars in CMD. [Seeking Refinement] View 1,718 Replies 9
Original Poster Posted 2007-04-02 03:17 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
After the current tests... If everyone thinks it's good, please give me extra points. Hehe

The progress bar display problem of copying files has been initially solved!

Advantage: start /min copy path:\file name path:\ to run in multi-threaded way.
Difficulty: The problem of obtaining the hard disk copy file rate.
I wrote a batch file as a test, and this value is bytes per microsecond / 86000 (the result of rounding up).
Note that different specifications of hard disks have different results.
Need everyone to test by themselves. (I have solved it myself, and using it as a progress bar prompt is to estimate the copy time)

Algorithm idea.

1. Use the dir command to obtain the file size of the copied file.
2. Divide the file size by the hard disk transfer rate to get the delay time of the animation.
3. Use this time to write the animation.

I will directly give this code in the first floor below.
Note: The code is streamlined, and the first step is omitted.. (Because it's an algorithm :)

[ Last edited by flyinspace on 2007-4-1 at 02:34 PM ]
知,不觉多。不知,乃求知
Floor 2 Posted 2007-04-02 03:17 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
@echo off & SetLocal EnableDelayedExpansion
set BackSpace=
set RateBar=□
set Rate=0
set AllFile=1
set ExistFile=0
set FileName=Test.rar
set /a FileSize=42719467
set /a CopySpeed=86500
set /a UseTime=%FileSize%/%CopySpeed%
set /a ShowTime=%UseTime%/100
set Rate_Num=0
set Space_Num=11
set /p=Copying file: , time required: %UseTime% microseconds<nul & echo.
echo ---------------------------------------------------
rem start /min FileName
set /p=Currently completed: <nul
for /l %%i in (0,1,100) do (
set /a output=%%i%%10
if "!output!"=="0" (
rem echo The %%i Time
set /p=!BackSpace!<nul
set /a Space_Num=!Space_Num!-1
set /a Rate_Num=!Rate_Num!+1
call :PutChar !Rate_Num! !Space_Num!
)
if %%i LSS 10 set /p=: %%i%%<nul
if %%i GEQ 10 set /p=: %%i%%<nul
call :ProcDelay %ShowTime%
set /p=<nul
)
echo.
echo Copy completed!
echo.

goto EXIT
::::::::::::::Output space:::::::::::::::::::::::
:PutChar _num_ _a_
for /l %%i in (1,1,%1) do (
rem echo !RateBar!
set /p=!RateBar!<nul
)

for /l %%i in (1,1,%2) do (
set /p= <nul
)


goto :EOF
::::::::::::::Delay subroutine:::::::::::::::::::::
:ProcDelay _Delay_
for /f "tokens=1-4 delims=:. " %%i in ("%time%") do set start=%%i%%j%%k%%l
:_TimeReturn_
for /f "tokens=1-4 delims=:. " %%i in ("%time%") do set end=%%i%%j%%k%%l
set /a s=%end%-%start%
if %s% LSS %1 goto _TimeReturn_
ENDLOCAL & GOTO :EOF
:EXIT
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
huzixuan +4 2007-04-02 07:01
知,不觉多。不知,乃求知
Floor 3 Posted 2007-04-02 03:55 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
In fact, many codes in this are borrowed from others.
For example, the delay subroutine. (Author unknown)

But others are based on the algorithms in C++.
It is completed by using the characteristics of set /p.

This program is different from the progress bars already available on the Internet.
It is practical.
知,不觉多。不知,乃求知
Floor 4 Posted 2007-04-02 04:06 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
The idea is good, but the hard disk transfer rate generally varies greatly with the file size, and the microsecond value is too small, batch processing basically can't reflect it, and milliseconds are barely acceptable

[ Last edited by zh159 on 2007-4-1 at 03:10 PM ]
Floor 5 Posted 2007-04-02 04:09 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
The idea raised by the upstairs is quite good.

Because it's proposing an algorithm.

So there's no judgment of errors...

In the actual batch processing example I wrote, my method is different...

If the size of the file is less than 86000 * 10, then there is no delay in the animation process...

2. For different hard drives, I obtain the speed of the hard drive based on the time taken to copy a cmd.exe to another disk as a reference...

3. Also, there is a judgment that if it's a copy within the same disk, the animation also has no delay.

This is the processing for practical application.

It's still in the testing phase, so I haven't shown it here.

The above algorithm is just to put forward my personal thoughts and discuss with everyone...

The actual code is already 32K in size...

And the testing is also very successful, but when copying very large files, it's a bit inaccurate, with an error of 1 to 3 seconds.

[ Last edited by flyinspace on 2007-4-1 at 03:27 PM ]
知,不觉多。不知,乃求知
Floor 6 Posted 2007-04-02 07:01 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 7 Posted 2007-04-02 09:34 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Where is there any confusion?
知,不觉多。不知,乃求知
Floor 8 Posted 2007-10-02 12:39 ·  美国 惠普公司
中级用户
★★
Credits 400
Posts 211
Joined 2007-09-30 18:02
18-year member
UID 98650
Gender Male
Status Offline
Running a command line X (such as COPY a large file) but it has to wait until it finishes to execute other code. Is there a way to make it execute and display with a progress bar at the same time?
Floor 9 Posted 2007-10-02 12:48 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 10 Posted 2009-01-12 15:02 ·  中国 上海 电信
初级用户
Credits 21
Posts 10
Joined 2007-03-30 02:03
19-year member
UID 83335
Gender Male
Status Offline
Where should I add the command:

xcopy c:\abc\*.* /s d:\aaa /y
Forum Jump: