batch counting files in folder output variabl

January 5, 2010 at 00:34:25
Specs: Windows 7
I am trying to make a batch file count the
number of files inside a folder and then output
the number to a variable so i can use it to
make a progress bar. Here a snippet of some
of the code i have so far

Set amount = dir %userin% /b/s/A-d | find "" /v 
/n /c
Set /a used = %used% + 1
Set /a progress = %used% * 100 / %amount%

Any ideas on how to fix this or any other ways
of doing it.

See More: batch counting files in folder output variabl

Report •

January 5, 2010 at 03:59:17
@echo off

set N=
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set /a N+=1

Helping others achieve escape felicity


Report •

January 5, 2010 at 09:22:11
or combine your approach with that of M2go:

for /f %%a in ('dir %userin% /b/s/A-d ^| find "" /v /c') do set amount=%%a

(not sure what you're doing with these)
Set /a used = %used% + 1
Set /a progress = %used% * 100 / %amount%

for a percent (based on 80-char screenwidth to use the foll. progress bar:)
::generate a new amount here...
set /a frx=ttlquant/80
set /a fry=amount/frx
for /L %%b in (1 1 %fry%) do set bar=%bar%%blok%
echo %bar%
if %fry% lss 80 goto :rpt

here's a progress-bar of sorts:
(this part needs to be at the very top of the script, not down in the body. it will write a small .com file to your drive.)
@goto :aaa
e100 B4 03 CD 10 80 FE 01 72 07 80 EE 01 B4 02 CD 10 CD 20 DB 0D
@echo off & setlocal
if exist goto :zero
debug <%0.bat 2>nul >nul
:: the rest of this can be put anywhere it's needed
:: this sets up the component of the bar
:: you could use any character for the component, such as _ or * or other "graphics" char.s
for /f "tokens=* delims=" %%a in ( do set blok=%%a
set blok=%blok:~-1%
set /a nn=1
set bb=
:: this just goes from 1 to 80, for demo/testing.
set bb=%bb%%blok%
echo %bb%
set /a nn+=1
if %nn% equ 80 goto :eof
goto :one

Report •
Related Solutions

Ask Question