Articles

Batch for Counting Files in a Directory

February 22, 2010 at 15:18:19
Specs: Windows XP

I am trying to run a batch file that if X or more files exist in a certain directory it outputs to a file..

This is what I have tried but it doesn't work thus far so any help would be great.

if exist ..\Outbound\T_*.db (
cd \
cd Retech\POst\Outbound
for /F %J in ('dir /A-D-H /B ^| find /C /V ""') do set /p count=%J
if %count% > 10 ( echo. >> Issue.log
echo Journal check occured at %time% >> Issue.log
ipconfig | find "IP Address" >> Issue.log
)
)


See More: Batch for Counting Files in a Directory

Report •


#1
February 22, 2010 at 20:28:10

It might just be your code structure and some syntax. here's the way i would write itup:
if not exist ..\Outbound\t*.db goto :eof
cd \Retech\POst\Outbound
for /F %%J in ('dir /A-D-H /B ^| find /C /V ""') do set count=%%J
if %count lss 11 goto :eof
echo. >> Issue.log
echo Journal check occured at %time%>> Issue.log
ipconfig | find "IP Address" >> Issue.log

Report •

#2
February 23, 2010 at 01:39:17

@echo off > newfile & setLocal enableDELAYedeXpansion

if not exist ..\Outbound\T_*.db goto :eof

set /a N=0
cd \Retech\POst\Outbound
for /f "tokens=* delims= " %%a in ('dir /A-D-H /B') do (
set /a N+=1
)

if !N! gtr 10 (
echo.
echo Journal check occured at %time%
ipconfig | find "IP Address"
) >> newfile


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions


Ask Question