Sign in to follow this  
Followers 0
SpecialK

How to read in a couple of lines from a text file?

3 posts in this topic

#1 ·  Posted (edited)

Hello,

i've already made some scripts with AutoIT 3 and they work fine.

But i never needed to read in some lines from a text or an ini file.

Now i need this but i don't have an idea how to realize it.

Here is a textfile for example:

Server1
Server2
Server3

How can i get each line to a variable?

For example:

$line1

$line2

$line3

Thank you for your help.

SpecialK

Edited by SpecialK

Share this post


Link to post
Share on other sites



You can try the "_FileReadToArray" function as below.

The code from help file :

#include <file.au3>
Dim $aRecords
If Not _FileReadToArray("error.log",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    Msgbox(0,'Record:' & $x, $aRecords[$x])
Next

oÝ÷ Ûú®¢×©äÊ£·ö÷¬¢[Þvl©®åzl"¶®¢Ò'u'¶*'ªê-"²¦ºé¬Â+aºw^®ËZاªëk+ºÙèÂØ^IÊâ¦Ü(®Kw^jëh×6
$var = IniReadSection ("test.ini", "Server")
If @error Then 
    MsgBox(4096, "", "INI Datei nicht gefunden") 
Else
    $notbremse= msgbox (17, "Server herunterfahren", "Achtung. Diese Datei fährt diverse Server herunter.", 10) 
    if $notbremse = 2 Then Exit

    For $i = 1 To $var[0][0] 
        Run ("shutdown.exe -m \\" & $var[$i][1] & " -s -t 10 -f") 
    Next
    
Sleep (60000)
    For $i = 1 To $var[0][0]
        Ping ( $var[$i][1] , 250)
        if @error = 0 Then
            msgbox (0, "Noch online", "Server " & $var[$i][1] & " ist noch online." & @CRLF & "Sende erneut Shutdown Befehl.", 10)
            Run ("shutdown.exe -m \\" & $var[$i][1] & " -s -t 10 -f")
        EndIf
    Next
            
EndIf

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