AutoHotkey Community

It is currently May 25th, 2012, 10:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: December 2nd, 2007, 3:15 am 
Offline

Joined: August 30th, 2007, 9:36 pm
Posts: 90
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 3:56 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
Code:
FileRead, file, YourFile.txt
StringSplit, File, File, `n
MsgBox, Your file has %File0% lines.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 4:26 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Whoa! That would create as many variables :shock:

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.

;
;
;
;
;
;


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2007, 1:34 pm 
Offline

Joined: May 1st, 2007, 8:36 pm
Posts: 83
Location: The Netherlands
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! 8)

_________________
Printing css/html-formatted text


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2007, 12:07 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
another way
Code:
Loop, Read, YourFile.txt
  numlines := A_Index

Msgbox, %numlines%

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2007, 12:25 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
That would be slower, but will consume less memory! :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: jyloup, lblb, ownmart, Pasukun, rbrtryn, RoAltmann, Xx7, Yahoo [Bot] and 62 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group