topten Posted May 7, 2016 Share Posted May 7, 2016 (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 May 7, 2016 by topten Link to comment Share on other sites More sharing options...
InunoTaishou Posted May 7, 2016 Share Posted May 7, 2016 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. Link to comment Share on other sites More sharing options...
Trong Posted May 7, 2016 Share Posted May 7, 2016 short: FileReadToArray() Regards, Link to comment Share on other sites More sharing options...
Developers Jos Posted May 7, 2016 Developers Share Posted May 7, 2016 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 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
topten Posted May 7, 2016 Author Share Posted May 7, 2016 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now