Sign in to follow this  
Followers 0
Clay

INI or other file iteration

6 posts in this topic

#1 ·  Posted (edited)

So its me again, with another question ...

Lets say I have a file with the follow structure

1: A,C,F

2: B,F,E

3: B,A,E

4: B,F,Z

and I wanted just like 3 and its contents and nothing else as in 3: B,A,E. ... how do I rip that from the file? is that possible ... or would I HAVE to read the entire file and then do a string compare by line?

EDIT: without using line numbers ... because the script will not know which sequence of strings it need before hand.

Edited by Clay

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

So its me again, with another question ...

Lets say I have a file with the follow structure

1: A,C,F

2: B,F,E

3: B,A,E

4: B,F,Z

and I wanted just like 3 and its contents and nothing else as in 3: B,A,E. ... how do I rip that from the file? is that possible ... or would I HAVE to read the entire file and then do a string compare by line?

The file will have to be searched somehow... I would suggest reading the lines to an array (_FileReadToArray), then just do a string comparison - as you explained - to find the line you are looking for. Edited by Airwolf123

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

a ini file should look like this

[something]

1=A,C,F

2=B,F,E

3=B,A,E

4=B,F,Z

iniread ($file, "something", "3")

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Pain,

Thanks for the help....but my point is that I don't want to use the INI file structure... my script runs successfully right now using an ini file but rather I would prefer comma seperated lists. As in:

1: A,C,F

2: B,F,E

3: B,A,E

4: B,F,Z

1,2,3,4 could easily be

This: A,C,F

That: B,F,E

And: A,S,E

This: B,F,Z

I just want to know if there is anyway to grap just one line from a file... for instance if I set a variable to "This", can i navigate through a file and grap the first instance of this in the file and return the entire line

Edited by Clay

Share this post


Link to post
Share on other sites

The backround method of doing this will always read the whole file first. Even things like FileReadLine() simply read the file and skip ahead x number of CRLF's. So to answer the question is simply depends on how virtualized you need your perception of the operation to be. If you wrap it in a function, it would appear like it's just doing magic (like any other way of doing it).

eg-

Global $filePath = @ScriptDir&"\some.txt"
$Result = GetLine("That")
MsgBox(0,"",$Result)


Func GetLine($Search)
    $i=1
    While 1
        $Line=FileReadLine($filePath,$i)
        if @error then
            Return 0
        EndIf
        If StringMid($Line,1,StringLen($Search))=$Search Then
            ExitLoop
        EndIf
        $i=$i+1
    WEnd
    Return $line
EndFunc

Share this post


Link to post
Share on other sites

StringRegExp(FileRead(filename), "(?s)(?i)(?m:^|\n)" & $sFindMe & ":).+?)", 1)

$sFindMe being the item to find (ie... 3 or "that")


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.

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