Jump to content

file size restrictions


satnad
 Share

Recommended Posts

I have a text file that is 15224 lines long. I am searching for a certain four character string within the whole document. I can confirm that the document scans to line 7424 but does not appear to pick up this character string after line 7424. Is there a line length or character length restriction or is there something else that I need to do. Thanks.

Link to comment
Share on other sites

How are you opening the file? With FileOpen? Or are you using FileReadToArray

Here is a copy of my script.

$FileFound = FileOpen ("FileFound.txt", 1)

$TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)

FileWrite ( $FileFound, $TimeStart & @CRLF)

For $D = 1 to 15224 Step 1

$insert = ""

$text = FileReadLine("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", $D)

If StringInStr ( $text, "22c8") then FileWrite ( $FileFound, $insert & $text & "North" & @CRLF)

Next

$TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)

FileWrite ( $FileFound, $TimeStop & @CRLF)

FileClose($FileFound)

exit

Link to comment
Share on other sites

Try this

$FileFound = FileOpen ("FileFound.txt", 1)
$TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)
FileWrite ( $FileFound, $TimeStart & @CRLF)

;Read the whole file to a variable
$fhandle = FileOpen("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", 0)
$alltext = FileRead($fhandle)
FileClose($fhandle)

;split the text in to an array
$alltextArray = StringSplit($alltext,@crlf,1)

;loop through the array (each line of text)
For $i = 1 to Ubound($alltextArray) -1
    $Insert=""; Mo idea why you have this because it is always blank!
    If StringInStr ($alltextArray[$i], "22c8") then FileWrite ( $FileFound, $insert & $alltextArray[$i] & "North" & @CRLF)
Next

$TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)
FileWrite ( $FileFound, $TimeStop & @CRLF)
FileClose($FileFound)
exit
Link to comment
Share on other sites

Try this

$FileFound = FileOpen ("FileFound.txt", 1)
$TimeStart = ( "Start" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)
FileWrite ( $FileFound, $TimeStart & @CRLF)

;Read the whole file to a variable
$fhandle = FileOpen("C:\Documents and Settings\satnad\Desktop\newattempt7NORTH.txt", 0)
$alltext = FileRead($fhandle)
FileClose($fhandle)

;split the text in to an array
$alltextArray = StringSplit($alltext,@crlf,1)

;loop through the array (each line of text)
For $i = 1 to Ubound($alltextArray) -1
    $Insert=""; Mo idea why you have this because it is always blank!
    If StringInStr ($alltextArray[$i], "22c8") then FileWrite ( $FileFound, $insert & $alltextArray[$i] & "North" & @CRLF)
Next

$TimeStop = ( "Stop" & " " & @YEAR & @MON & @MDAY & " " & @HOUR & @MIN & @SEC)
FileWrite ( $FileFound, $TimeStop & @CRLF)
FileClose($FileFound)
exit
ChrisL: Tried your script. It keeps giving me an error at the line "$alltext = FileRead($fhandle)" saying there is an Incorrect number of parameters in the function call. If I change this line to say "$alltext = FileRead($fhandle, 64000)" it searches great but I would then have to check the number of characters each in file I want to check and edit the script accordingly. As far as the $Insert = "", this is just a piece of a scipt I am writing. I have narrowed my problem down to this section and this $Insert can be eliminated from this segment of script for now. You have solved my problem with this script and I thank you for that, any suggestion as how to get rid of the last error of Incorrect number of parameters? I looked in the help and it is asking for the number of characters to be read and there doesn't seem to be an option to read the entire file. Satnad
Link to comment
Share on other sites

  • Moderators

Just use _FileReadToArray() as suggested... you won't have to read every line individually as they will all be read and put in an array, then just loop through the array as you're doing above... No fuss no muss.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

ChrisL: Tried your script. It keeps giving me an error at the line "$alltext = It keeps giving me an error at the line "$alltext = FileRead($fhandle)" saying there is an Incorrect number of parameters in the function call

Hi,

Strange;

Please post an example txt file where this occurs.

Maybe check you have latest version of AutoIt; ; ? what number/ There was an error in one version some time back with fileread.

Best, randall

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...