Jump to content

Recommended Posts

Posted

Hello. I need your help. I want to split Data from a txt File.

I have a txt file which content is this:

Test.txt :

username:passwort

username2:passwort2

username3:passwort3

username4:passwort4

I want to have the username and the passwort of every line.

Can somebody help me PLSSSS?

How to open a file i know, but how to split the usernames and passworts i dont know.

cu,

peter

Posted (edited)

Hello. I need your help. I want to split Data from a txt File.

I have a txt file which content is this:

Test.txt :

I want to have the username and the passwort of every line.

Can somebody help me PLSSSS?

How to open a file i know, but how to split the usernames and passworts i dont know.

cu,

peter

$FILE_OPEN = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)
$FILE = FileOpen($FILE_OPEN,0)
$INDEX = 1
While 1
    $LINE = FileReadLine($FILE,$INDEX)
    If @error Then ExitLoop
    $INDEX += 1
    $SPLIT = StringSplit($LINE,":")
    If IsArray($SPLIT) Then
        MsgBox(0,"",$SPLIT[1] & @CRLF & $SPLIT[2])
    EndIf
WEnd
FileClose($FILE)

EDIT: $SPLIT[1] is username and $SPLIT[2] is password

Edited by Andreik
Posted

$FILE_OPEN = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)
$FILE = FileOpen($FILE_OPEN,0)
$INDEX = 1
While 1
    $LINE = FileReadLine($FILE,$INDEX)
    If @error Then ExitLoop
    $INDEX += 1
    $SPLIT = StringSplit($LINE,":")
    If IsArray($SPLIT) Then
        MsgBox(0,"",$SPLIT[1] & @CRLF & $SPLIT[2])
    EndIf
WEnd
FileClose($FILE)

EDIT: $SPLIT[1] is username and $SPLIT[2] is password

You are the best !!!!!

Thank you !

How i can run a function till there are no more Usernames and Passworts?

Example:

I have the List :

username:passwort

username2:passwort2

username3:passwort3

username4:passwort4

How i can run the function login 4 times with the 4 data?
Posted (edited)

You are the best !!!!!

Thank you !

How i can run a function till there are no more Usernames and Passworts?

Example:

I have the List :

How i can run the function login 4 times with the 4 data?

If you saw in my example, after FileReadLine() function is If @error Then ExitLoop. This mean if you have in your file 4 lines, when the script will try to read the line 5 (this doesn't exists) will gave an error and script will exit from loop.

So you can use this script for any number of lines. :)

Edited by Andreik
Posted

Thanks at all this is my solution:

Func Test()

$FILE_OPEN = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)

$FILE = FileOpen($FILE_OPEN,0)

$INDEX = 1

While 1

$LINE = FileReadLine($FILE,$INDEX)

If @error Then ExitLoop

$INDEX += 1

$SPLIT = StringSplit($LINE,":")

If IsArray($SPLIT) Then

login($SPLIT[1],$SPLIT[2])

EndIf

WEnd

FileClose($FILE)

EndFunc

Posted

Thanks at all this is my solution:

;-))

This is mine:

#Include <File.au3>
$file = "c:\user_pw.txt"

if Not _FileReadToArray ($file, $temparray) Then
    MsgBox(4096,"Error", " Error reading " & $file & " to Array     error:" & @error)
    Exit
Else
    For $i = 1 To UBound ($temparray) - 1
        $split = StringSplit ($temparray [$i], ":")
        login ( $split [1], $split [2] )
    Next
EndIf

Func login ($username, $password)
    do what you want
EndFunc

Stefan

Posted (edited)

I don't understand what you want to say with FileClose($FILE) is useless.

Here is a modified version to show when file is open.

If I`m wrong please explain me where. :)

$FILE_OPEN = FileOpenDialog("SELECT",@ScriptDir,"All (*.*)",1)
$FILE = FileOpen($FILE_OPEN,0)
MsgBox(0,"","File is open: " & IsOpen($FILE_OPEN))
$INDEX = 1
While 1
    $LINE = FileReadLine($FILE,$INDEX)
    If @error Then ExitLoop
    $INDEX += 1
    $SPLIT = StringSplit($LINE,":")
    If IsArray($SPLIT) Then
        MsgBox(0,"",$SPLIT[1] & @CRLF & $SPLIT[2])
    EndIf
WEnd
MsgBox(0,"","File is open: " & IsOpen($FILE_OPEN))
FileClose($FILE)
MsgBox(0,"","File is open: " & IsOpen($FILE_OPEN))

Func IsOpen($FILE)
$GENERIC_READ  = 0x80000000
$GENERIC_WRITE = 0x40000000
$OPEN_EXISTING = 3
$FILE_ATTRIBUTE_NORMAL = 0x80
If Not FileExists($FILE) Then Exit
$hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _
                  "str", $FILE, _
                  "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _
                  "int", 0, _
                  "ptr", 0, _
                  "int", $OPEN_EXISTING, _
                  "int", $FILE_ATTRIBUTE_NORMAL, _
                  "int", 0)

If $hFile[0] = -1 Then
    Return True
Else
    Return False
EndIf
EndFunc
Edited by Andreik

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
×
×
  • Create New...