On Friday, May 24, 2013 10:37:17 PM UTC-7, Todd Vargo wrote:
> On 5/24/2013 5:19 PM,
phil.r...@gmail.com wrote:
>
> >>
>
> >>
>
> >> Note, using standard batch commands will not will not show progress for
>
> >>
>
> >> copying a single large file because there is no intrinsic provision to
>
> >>
>
> >> copy a file broken down in increments. A special utility (ie. vbscript
>
> >>
>
> >> or other) would need to be written to break a large file down and
>
> >>
>
> >> provide its own progress report.
>
> >>
>
> >
>
> > Hi, Todd,
>
> >
>
> > For a single large file, you can just examine the number of bytes
>
> > copied every few seconds by comparing current and previous (from a
>
> > few seconds ago) file size information.
>
> >
>
> > Here's a 'sliding bar' progress indicator. No percentages, just an
>
> > indication that something is going on. You can try it without the
>
> > sub-second delay provided by the call to VBSleep in line 21, but the
>
> > on-screen appearance will suffer greatly. The variable 'fragment' is
>
> > supposed to be four x'B2' characters.
>
> >
>
> > =====begin c:\CMD\DEMO\SlidingBar.cmd ====================
>
> > 01. @echo off
>
> > 02. setlocal enabledelayedexpansion
>
> > 03. set "fragment=����"
Perhaps I should have been more explicit. Never claimed that this particular
example would quantitatively show progress; rather, it shows that something
is happening, like the spinners, etc., which don't quantitatively show
progress either. My suggestion about how to monitor the copying of a large
file by monitoring the ever-increasing size of the destination file was
just a thought awaiting implementation. I'm sorry if you thought that this
particular example was offered as a solution for your 'copy-a-single-file'
case.
>
> In order to function the way you suggest, the file would have to be
>
> copied in a separate process while being monitored in the current cmd
>
> session. I'm not saying that is a good or bad thing, I'm just saying the
>
> code above does not do what was commented on. We both know it can be
>
> written but the OP has not stated what sort of lengthy progress is being
>
> measured in order to to offer an applicable example. We could post a
>
> dozen examples and have none of them match what the OP wants to use it for.
>
>
>
> FWIW, I have never liked wait indicators pretending to be progress
>
> indicators. All of the batch examples I have ever seen posted use time
>
> delays to simulate progress, but never any connection to actual progress
>
> being performed. (ie. progress during an actual file or group of files
>
> being copied, moved, renamed or other real batch activity) This is
>
> largely due to OPs only asking how to display an indicator but never ask
>
> how to apply one for a practical use.
I am in total agreement with you. I much prefer a process that actually
displays real progress in a quantitative way (see below).
>
>
>
> BTW, the "call VBSleep 15" line could be replaced with a PING timer to
>
> eliminate the need for the VBSleep.cmd batch. Just my 2 cents.
A ping timer slows the whole process down too much. A sub-second delay is
what is required to make it look halfway decent on screen.
Here's one that PRETENDS to copy a bunch of files (just for demonstration
purposes). BTW, the font I use for my console windows is Lucida Console;
=====begin h:\cmd\test\progress.cmd ====================
01. @echo off
02. setlocal enabledelayedexpansion
03. set filespec=%*
04. :: save lines and columns values for current console window
05. for /f "tokens=2" %%a in (
06. 'mode con ^| find "Lines:"'
07. ) do set lines=%%a
08. for /f "tokens=2" %%a in (
09. 'mode con ^| find "Columns:"'
10. ) do set columns=%%a
11. :: bigbar is supposed to be 50 x'DB' characters:
12. set "bigbar=██████████████████████████████████████████████████"
13. set "spaces= "
14. ::
15. :: Instead of simply displaying dots on the screen, we are
16. :: going to PRETEND to copy some files while displaying
17. :: a progress bar showing how much 'work' has been 'done'.
18. ::
19. :: First, get a list of a bunch of files that we're going
20. :: to PRETEND to copy and count how many files there are
21. :: in the list so we know how much work needs to be done
22.
23. for /f "tokens=1" %%a in (
24. 'dir /s /b /a-d "%filespec%" ^| find /v /c ""'
25. ) do set total_files=%%a
26.
27.
28. set files_copied=0
29. set /a x = total_files*10
30.
31. :: in order to make the CLS less objectionable (if that's
32. :: possible), we shrink the current console window:
33. mode con lines=13 cols=60
34.
35. for /f "tokens=*" %%a in (
36. 'dir /s /b /a-d "%filespec%"'
37. ) do call :MAIN "%%a"
38. echo Press any key to FINISH
39. pause > nul
40. :: restore the previous console lines and columns settings:
41. mode con lines=%lines% cols=%columns%
42. goto :EOF
43.
44. :MAIN
45.
46. set "filename=%~1"
47. set /a files_copied+=1
48. set y=%files_copied%000
49. set /a pct_done = y/x
50. set blength=%pct_done%
51.
52. :: force the progress bar to show SOMETHING at the very
53. :: beginning; otherwise, when the total number of files
54. :: is very large, nothing will show on the bar for a
55. :: bunch of iterations at the beginning of the process.
56. if 10 LSS %pct_done% set /a blength/=2
57.
58. set progress=!bigbar:~0,%blength%!%spaces%
59. set tdisp=%total_files%%spaces:~0,10%
60. set cdisp=%files_copied%%spaces:~0,10%
61. set ndisp=%filename%%spaces%
62. set "pdisp=%%"
63. set "pdisp= !pct_done!!pdisp!"
64. cls
65. :: ....+....1....+....2....+....3....+....4....+....5....+....6
66. echo/╔══╤══════════════════════════════════════════════════╤═══╗
67. echo/║ │%progress:~0,50%│ ║
68. echo/╟──┴──────────────────────────────────────────────────┴───║
69. echo/║ Copying %ndisp:~0,30% ║
70. echo/║ ║
71. echo/║ total: %tdisp:~0,6% copied: %cdisp:~0,6% ║
72. echo/║ ║
73. echo/║ %pdisp:~-4% complete ║
74. echo/╚═════════════════════════════════════════════════════════╝
75. :: Here is where we would copy "%filename%" x:\path\dir\ > nul
76. :: if we were actually copying the files for real
77. ::
78. :: But since we aren't actually copying any files, we need to
79. :: slow down this demo just a bit by waiting for a short time
80. :: between iterations of this subroutine. A 'ping localhost'
81. :: delay of one second would be too long and make the demo
82. :: too boring and unrealistic, so we need a subsecond delay:
83. call VBSleep 75
84. goto :EOF
=====end h:\cmd\test\progress.cmd ====================
Again, without a sub-second delay (line 83), the on-screen appearance
is not as good.