中国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-11 04:34
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Discussion] Issues with Practicalizing Progress Bars in CMD. [Seeking Refinement]
Printable Version  1,717 / 9
Floor1 flyinspace Posted 2007-04-02 03:17
银牌会员 Posts 517 Credits 1,206
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 ]
Floor2 flyinspace Posted 2007-04-02 03:17
银牌会员 Posts 517 Credits 1,206
@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
Floor3 flyinspace Posted 2007-04-02 03:55
银牌会员 Posts 517 Credits 1,206
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.
Floor4 zh159 Posted 2007-04-02 04:06
金牌会员 Posts 1,467 Credits 3,687
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 ]
Floor5 flyinspace Posted 2007-04-02 04:09
银牌会员 Posts 517 Credits 1,206
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 ]
Floor6 huzixuan Posted 2007-04-02 07:01
高级用户 Posts 219 Credits 537 From 芜湖
Floor7 flyinspace Posted 2007-04-02 09:34
银牌会员 Posts 517 Credits 1,206
Where is there any confusion?
Floor8 uiopuiop Posted 2007-10-02 12:39
中级用户 Posts 211 Credits 400
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?
Floor9 electronixtar Posted 2007-10-02 12:48
铂金会员 Posts 2,672 Credits 7,493
Floor10 jaceyxp Posted 2009-01-12 15:02
初级用户 Posts 10 Credits 21
Where should I add the command:

xcopy c:\abc\*.* /s d:\aaa /y
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023