topten

FileReadLine to Variable, any way do it faster? [solved]

5 posts in this topic

#1 ·  Posted (edited)

I have a script, where I need to read file line by line to a variable (80000 lines) takes it forever to do it. Is any way to make it faster?

Local $hFileOpen = FileOpen($SelectFile, $FO_READ)
$str = ""
  for $i = 1 to $num ; ~about 80000 lines
    Local $sFileRead = FileReadLine($hFileOpen, $i)
    $str = $str&$sFileRead
  next

Great thanx in advance!

Edited by topten

Share this post


Link to post
Share on other sites



What kind of data are you trying to read from the file?

Why are you doing it a line at at time when you're just appending it to a string without the line feed?

Local $hFileOpen = FileOpen($SelectFile, $FO_READ)
Local $sStr = ""
If ($hFileOpen) Then
    $sStr = StringRegExpReplace(FileRead($hFileOpen), "[\r\n]", "")
    FileClose($hFileOpen)
EndIf

This will do the same thing.

Share this post


Link to post
Share on other sites

short:

FileReadToArray()

 


“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites

How much faster is this version for you?

Local $hFileOpen = FileOpen($SelectFile, $FO_READ)
$str = ""
for $i = 1 to $num ; ~about 80000 lines
    $str&= FileReadLine($hFileOpen)
next

Or else try this:

Local $str = FileRead($SelectFile)
$str = StringReplace($str,@crlf,"")

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Great thanx  InunoTaishou,  Trong, Jos !

It works now much better :)

42 minutes ago, Jos said:

How much faster is this version for you?

Local $hFileOpen = FileOpen($SelectFile, $FO_READ)
$str = ""
for $i = 1 to $num ; ~about 80000 lines
    $str&= FileReadLine($hFileOpen)
next

This one is say, 3-5 times faster than mine

 

 

Or else try this:

Local $str = FileRead($SelectFile)
$str = StringReplace($str,@crlf,"")

This one is about 20-30  times faster than mine

 

Share this post


Link to post
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