Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all,
I'm a beginner in batch files. I'm trying to read how many lines are in a file(lets say test.txt), store this number in a variable and depending on the value of this variable I will run Script1 or Script2:
I put
Set Lines=find /C < test.txt
If Lines =< 12 CALL Sript1
If Lines >12 CALL Script2I know that even the first line doesn't work, any help, I have also another issue since my OS is W2k do I have to erase this temporary variables at the end or to be aware of somthing when I'm running batch files on W2K.
Thank you

The script that fits your need is the following
(Type CFind File_Name to run, assumed CFind.bat is the script)@Echo Off
For /F "tokens=2 delims=:" %%A in ('Find /C /V ^"$@?^" %1') Do Set Lines=%%A
If %Lines% leq 12 Call Script1
If %Lines% gtr 12 Call Script2Set Lines=
The For /F statement fits one line without CR/LF.
The last command erases the variable and it is a good practice to clean up before leaving. Anyway the script language for Win NT/2K/XP is a superset of the DOS batch one, more powerfull, but more complex too.
I guess you need deeper exposure to the issue.

Hi Ivo,
The batch doesn't work like It should, for this file:Volume Name State Last Update Automated
Date/Time LibName
-------------------------
000017 Mountable 01-09-2004 14:03:29 LIBRARY1
000027 Mountable 01-09-2004 13:29:08 LIBRARY1Lines is equal=6, Since me I want just to look for the lines begining with 00 I do: find /c "00" so lines has the value of 0 which is not true
Any Idea
Thanks

Have you replaced ('Find /C /V ^"$@?^" %1') with ('Find /C ^"00^" %1')? Otherwise you get 0 in the Lines variable as /V forces to count lines NOT holding the string and the ^ (caret) is required inside a compound (For /F) command.
Following my tip your script should work.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |