Jump to content

Need helps counting lines.


Recommended Posts

#include <file.au3>
;$version & $Filetosearch
;Msgbox(0, "c00", $c00 & $version)
;===============================================================================
;
; Description:      Returns the number of lines in the specified file.
; Syntax:           _FileCountLines( $sFilePath )
; Parameter(s):     $sFilePath - Path and filename of the file to be read
; Requirement(s):   None
; Return Value(s):  On Success - Returns number of lines in the file
;                   On Failure - Returns 0 and sets @error = 1
; Author(s):        Tylo <tylo at start dot no>
; Note(s):          It does not count a final @LF as a line.
;
;===============================================================================
Dim $file

$file = fileopen("C:\wfx32\failed50702.log",0)
$sFilePath = fileopen ("c:\wfx32\failed50702.log",0)
global $me = 0
for $me = 1 to 10  step 1
_filecountlines($file)
; end of Filecount lines.
msgbox(0,"time", $me)
msgbox(0,"test", $file)
Next
;$file = fileclose("C:\wfx32\failed50702.log",0)

Output is 1 What am i doing wrong? i know theres close to 50 lines in this text....

Link to comment
Share on other sites

HI,

why not using _FileReadToArray and then have a look at [0]

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

HI,

why not using _FileReadToArray and then have a look at [0]

So long,

Mega

CODE

#include <file.au3>

Dim $file

dim $aarray[1]

$file = fileopen("C:\wfx32\failed50702.log",0)

$sFilePath = "c:\wfx32\failed50702.log"

_FileReadToArray($sFilePath,$aArray)

msgbox(0,"test", $aArray)

;$file = fileclose("C:\wfx32\failed50702.log",0)

what am i doing wrong? Edited by blacksniper
Link to comment
Share on other sites

The help file gives a real good exampler of _FileReadToArray()

#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("error.log",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    Msgbox(0,'Record:' & $x, $aRecords[$x])
Next

Maybe use that and change it to fit your needs

EDIT - to get the index number of the array it would be Msgbox(0,'Number of records',$aRecords[0])

EDIT2 - After reading this - I agree and would use this to get the # of lines

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

...Output is 1 What am i doing wrong? i know theres close to 50 lines in this text....

_filecountlines requires a file path

you fed it a file handle

Edit1: plus you did not feed the output of _filecountlines into a variable...

Edit2: http://www.autoitscript.com/forum/index.ph...ost&p=44449 talks of the speed diff between arrays vs the method used in _filecountlines

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...