Batch file count

March 12, 2011 at 20:09:13
Specs: Windows Vista
I WANT A HELP TO WRITE A BATCH FILE TO DISPLAY THE NUMBER OF FILES IN A DIRECTORY BEFORE DELETE THEM. THANK
BESIDES IS IT POSSIBLE TO RUN A BATCH FILE IN WEEKDAY AUTOMATICALLY.

See More: Batch file count

Report •


#1
March 13, 2011 at 04:17:51
try this .. Create a batch file in the same flder and put below.
--------------------------------------------------------------------------
@echo off & setlocal enabledelayedexpansion
set /a count=1
for /f %%a in ('dir /b *.*') do (
set /a count=count + 1
)
echo Total number of files - !count!
------------------------------------------------------

it will display the total number of files..You can schedle it in windows task schedler to run weekly.
It will not delete anything , if you want to delete the files then run "erase /?" from a command line and put appropriate command at the end of batch file.

Subhash Chandra.


Report •

#2
March 13, 2011 at 04:18:45
try this .. Create a batch file in the same flder and put below.
--------------------------------------------------------------------------
@echo off & setlocal enabledelayedexpansion
set /a count=1
for /f %%a in ('dir /b *.*') do (
set /a count=count + 1
)
echo Total number of files - !count!
------------------------------------------------------

it will display the total number of files..You can schedle it in windows task schedler to run weekly.
It will not delete anything , if you want to delete the files then run "erase /?" from a command line and put appropriate command at the end of batch file.

** I dont see a reson for you to shout in the forum,I think you know using Caps is known as shoting in internet world..

Subhash Chandra.


Report •

#3
March 19, 2011 at 22:14:29
Subhash Chandra.
i respect those like u much who do not receive any substantial benefit but offer help to those green hands of computer users
thanks

Report •

Related Solutions

#4
March 20, 2011 at 15:11:03
@subhash chandra,

Line 4: set /a count=count + 1

Must be: set /a count=%count% + 1

Happy is ONE who says I am an OttoMAN.


Report •

#5
March 20, 2011 at 16:06:09
@MUs

Actually that is valid use, "set /a" doesn't require variable names to be expanded(except dynamic variables like %random%):

From "set /?"

.... Any non-numeric strings in the
expression are treated as environment variable names whose values are
converted to numbers before using them.  If an environment variable name
is specified but is not defined in the current environment, then a value
of zero is used.  This allows you to do arithmetic with environment
variable values without having to type all those % signs to get their
values.  ....


Furthermore using a standard environment variable will break the script because of variable expansion issues.

Valid, equivalent and functional it the situation:

set /a count += 1
set /a count=count + 1 
set /a count=!count! + 1


Report •

#6
March 20, 2011 at 16:43:08
hello MU and Judago,

Thanks for your guidence..

Subhash Chandra.


Report •

#7
March 21, 2011 at 00:59:14
@Judago,

I never full read the 'set /?' LOL.

Thanks :)

Happy is ONE who says I am an OttoMAN.


Report •


Ask Question