Sign in to follow this  
Followers 0
Command3r

[HELP] File read all lines except last 1

6 posts in this topic

Hello scripters :) i got another problem reading all lines in txt file except the last one.

I dont want to write how many lines to read just reading all except the last whatever how many it is.

My efforts:

#include <file.au3>
$file = @ScriptDir & "\x.txt"
$ReadLines = FileReadLine($file)

Local $Read
_FileReadToArray($file, $Read)
For $i = 1 To $Read - 1 ; with-1 or without-1 the result is the same
MsgBox(0, $i, $Read - 1)
Next

Question here: "Why first msgbox title is "1" ? and how can i avoid that?"

#include <file.au3>
$file = @ScriptDir & "\x.txt"
$ReadLines = FileReadLine($file)

Local $Read
_FileReadToArray($file, $Read)
For $i = 1 To $Read
MsgBox(0, $i, $Read[0] -1) ; here in msg's text resolved but in title not :D i think the problem from $i ??
Next

[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

Share this post


Link to post
Share on other sites



Try it this way - For $i = 1 To $Read[0] - 1

example:

#include <file.au3>
Local $Read, $file = "x.txt"

_FileReadToArray($file, $Read)

For $i = 1 To $Read[0] - 1
    ConsoleWrite($i & " - " & $Read[$i] & @LF)
Next

x.txt

line 1
line 2
line 3
line 4
line 5

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Awesome!!!! it's working !! :)

Thanks somdcomputerguy


[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

Share this post


Link to post
Share on other sites

Command3r,

To answer your 2ND question: The 2nd parm of MSGBOX is the title. You have $i as the second parm so the title will be whatever the value of $i is.

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

You bet. Good luck with your project.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

@kylomas

mmm... you're right ! thanks.:)

@somdcomputerguy

thanks again. ;)


[font="arial, helvetica, sans-serif;"]Advice for you[/font][font="arial, helvetica, sans-serif;"]: [/font][u]Search[/u] before posting.

 

[font="arial, helvetica, sans-serif;"] *********** Problem solved? if yes [/font][color=rgb(0,0,0);font-family:arial, helvetica, sans-serif;] *********[/color]

[font="arial, helvetica, sans-serif;"]******* press "Mark Solved" button. *******[/font]

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
Sign in to follow this  
Followers 0

  • Similar Content

    • wimhek
      By wimhek
      Is it possible , and how can I read and write txt files from Icloud (apple service) ?
      Let me try to explain my application.
      On my Ipad and Iphone I create txt files. On my windows computer it is possible to read and modify these files manually, by logging in on www.icloud.com.
      What I want to make is an auto-it script who reads the txt file and create an new txt file on www.icloud.com,  so I can acces these on my ipad and/or phone.
       
      Thank you.
    • fopetesl
      By fopetesl
      Attempting to extract data from CSV file to display in _ExtMsgBox, sometimes it works fine but mostly it fails with Error:
      3 - File lines have different numbers of fields (only if $FRTA_INTARRAYS flag not set) I have tried all the available $iFlags combinations without success.
      The CSV file format is fixed for any data collected, sample attached. The two CSV MsgBox() show correct file name
      $sText = "" Global $aLines, $fFile, $fLine, $fFcopy $fFile = FileOpen ( "QuickPlotData.dat", 0 ) ; find current CSV file $fLine = FileReadLine ( $fFile ) ; read correct CSV file name MsgBox(0,"CSV file: ", $fLine) ; Read file to 2D array MsgBox(0,"CSV[2] file: ", $fLine) ; _FileReadToArray($fLine, $aLines) ; 'simple' call _FileReadToArray($fLine, $aLines,$FRTA_NOCOUNT+$FRTA_ENTIRESPLIT,',') If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR!", "CSV read error " & @error) exit(0) EndIf _ArrayDisplay($aLines)  
      ZZj2_Test.Won.Two.csv
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • antmar904
      By antmar904
      Hi,
      I ran a remote program on 180 computers and logged the output to a log file with paexec.  I'm trying to parse through the log file to see which computers launched the program successfully and record the computer name but I'm not sure how to go about it. 
      I can successfully open the log file, read it but not sure how to start separating the data.
      I've attached the log file, basically every computer entry in the log file for a new computer starts with "Connecting to <computername>..." I was thinking about using that as the start and stop point for retrieving the end results.  Anything with a "returned 0" is a success, everything is a fail.
      Any help is much appreciated.
      testlogfile.txt
    • MrSparty1995
      By MrSparty1995
      I have a good handle on how to read a file line by line, and search for a given string.
      Basically using, FileOpen, FileReadLine, and StringInStr.
      I have been trying to figure out why my search keeps coming back with no match.
      For example, if my string line was "Where is Waldy", and I was searching for Waldy that comes back fine.
      But in my file, Let's say it is
      Where is "Waldy"
      So i read that line in and do a search for Waldy, but i comes back with no match since there is quotes around it.
      Is there a way to resolve this?
      Here is my actual example
      The line comes back like this
          <JposEntry logicalName="LineDisp_iSC480">
      I'm searching for LineDisp_iSC480, but its coming back with no match due to the quotes.
      Thanks in advance, James