Piping file count into variable

May 14, 2009 at 08:58:45
Specs: Windows server 2003
I want get a file count in a log directory and then pipe it into a variable. Then I check the value and then it fails or pass depending on the number.
I have this code:
dir /a-d C:\logs /b/s |find /v /c "*.*" > %count%

See More: Piping file count into variable

Report •

May 14, 2009 at 10:52:06
@echo off > newfile & setLocal EnableDelayedExpansion

set /a N=0
for /f "tokens=* delims= " %%a in ('dir/s/b/a-d C:\logs') do (
set /a N+=1

echo !N! files

If at first you don't succeed, you're about average.


Report •

June 1, 2009 at 10:18:13
I need to do a 'findstr' in an sftp log. Can this code be modified to find the # of matches in the log file? Create the variable? The sftp log does not display the 'transfer complete' statement' so I will do an 'ls' and based on the number matching strings in the log I will fail or succeed based on the variable. The code you created worked very well. Thx.

Report •

Related Solutions

Ask Question