| View previous topic :: View next topic |
| Author |
Message |
chipmanners
Joined: 30 Aug 2007 Posts: 70
|
Posted: Sun Dec 02, 2007 3:15 am Post subject: counting lines in text file |
|
|
hi,
Im looking to count the number of lines in a text file and return it as a variable. Is there a way to do this?
Thanks,
Chip |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 2556
|
Posted: Sun Dec 02, 2007 3:56 am Post subject: |
|
|
| Code: | FileRead, file, YourFile.txt
StringSplit, File, File, `n
MsgBox, Your file has %File0% lines. |
_________________ My Home Thread
Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7609
|
Posted: Sun Dec 02, 2007 4:26 am Post subject: |
|
|
Whoa! That would create as many variables
Better to use StringReplace:
| Code: | FileRead, Var, %A_ScriptFullPath%
StringReplace, Var, Var, `n,`n, UseErrorLevel
Lines := ErrorLevel+1
Var= ; empty it
MsgBox, %A_ScriptFullPath%`ncontains %Lines% lines.
;
;
;
;
;
; |
 |
|
| Back to top |
|
 |
Wouther
Joined: 01 May 2007 Posts: 83 Location: The Netherlands
|
Posted: Sun Dec 02, 2007 1:34 pm Post subject: |
|
|
| Skan wrote: | | Code: | FileRead, Var, %A_ScriptFullPath%
StringReplace, Var, Var, `n,`n, UseErrorLevel
Lines := ErrorLevel+1
Var= ; empty it
MsgBox, %A_ScriptFullPath%`ncontains %Lines% lines. |
|
Woah! Just what I needed! Thanks!  _________________ Printing css/html-formatted text |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 7703 Location: Madison, WI
|
Posted: Tue Dec 04, 2007 12:07 am Post subject: |
|
|
another way
| Code: |
Loop, Read, YourFile.txt
numlines := A_Index
Msgbox, %numlines%
|
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7609
|
Posted: Tue Dec 04, 2007 12:25 am Post subject: |
|
|
That would be slower, but will consume less memory!  |
|
| Back to top |
|
 |
|