Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Help

Status
Not open for further replies.

jjtbt

MIS
Sep 26, 2001
57
US
I am using Windows 2000 and trying to create a batch file that will set a variable named "TOTFILES" to the number of files found in a folder called "c:\test". I then want it to output "GREATERTHAN4" if the number of files found in the folder is greater than 4.

Here is the test batch file I have been playing around with:

@echo off
for /f %%c in ('dir "C:\test" /b ^| find /c /v "UnLiKeLy To ExIsT"') do set TOTFILES=%%c
If %TOTFILES GTR 4 ECHO GREATERTHAN4

It appears to set the variable "TOTFILES", but it gives me the output "GREATERTHAN4" no matter how many files are in the folder "c:\test".

Any ideas?
 
For one, it appears that you're missing a % sign after
%TOTFILES, unless that's a typo. I believe you should have it like so:

@echo off
for /f %%c in ('dir "C:\test" /b ^| find /c /v "UnLiKeLy To ExIsT"') do set TOTFILES=%%c
If %TOTFILES% GTR 4 ECHO GREATERTHAN4

 
Well, that was an easy one! It's working perfect now, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top