Page 1 of 1 1
Topic Options
#159548 - 2006-03-21 02:57 PM Counting rows in txt files
Dany_Many Offline
Lurker

Registered: 2006-03-21
Posts: 3
Loc: Rijeka, Croatia, Europe
Hi

plz i nead help. First sorry for my terreble english.

I'm a beginner in kix.
Cann someone make me a script that counts rows in txt file.
If file contains 1 or 2 or 3 or 4 continue.
If file contains 5 rows delete it, and execute some program.

Cann someone help me plz.
Tnx in advance

Dejan

Top
#159549 - 2006-03-21 03:03 PM Re: Counting rows in txt files
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Hi and welcome to this board.

You mean something like this?

Code:

$file = "c:\somefile.txt"
$lines = 0
$rc = Open (1, $file, 2)
$line = ReadLine (1)
;
While @ERROR = "0"
$lines = $lines + 1
$line = ReadLine (1)
Loop
;
$rc = Close (1)
;
If $lines > 4
Del $file
Run "some program"
Else
?"Files has " $lines " lines. Do nothing."
EndIf



[edit]
Removed a typo in the code.
[/edit]


Edited by Mart (2006-03-21 03:06 PM)

Top
#159550 - 2006-03-21 03:06 PM Re: Counting rows in txt files
Dany_Many Offline
Lurker

Registered: 2006-03-21
Posts: 3
Loc: Rijeka, Croatia, Europe
Wow, what a speed of anwsering.
Tnx very much for code, i'm going to test it now, and post the result.:))

Top
#159551 - 2006-03-21 03:08 PM Re: Counting rows in txt files
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You did see that I edited the post at the same time you posted your reply?
There was a typo in the code that stopped it from working properly.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#159552 - 2006-03-21 03:21 PM Re: Counting rows in txt files
Dany_Many Offline
Lurker

Registered: 2006-03-21
Posts: 3
Loc: Rijeka, Croatia, Europe
yes, offcourse:)) i tried it, and it didn't work properly. Now everything in my life works ok:))))))). tnx again.
Top
#159553 - 2006-03-21 04:14 PM Re: Counting rows in txt files
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Happy to help.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#159554 - 2006-03-23 05:06 AM Re: Counting rows in txt files
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Using the ReadFile UDF we could do
Code:

$lines=ubound(readfile('c:\somefile.txt'))-1

_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.063 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org