peter233 Posted February 4, 2009 Share Posted February 4, 2009 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:passwortusername2:passwort2username3:passwort3username4:passwort4I 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 Link to comment Share on other sites More sharing options...
Andreik Posted February 4, 2009 Share Posted February 4, 2009 (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 February 4, 2009 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
peter233 Posted February 4, 2009 Author Share Posted February 4, 2009 $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 passwordYou 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? Link to comment Share on other sites More sharing options...
Andreik Posted February 4, 2009 Share Posted February 4, 2009 (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 February 4, 2009 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
peter233 Posted February 4, 2009 Author Share Posted February 4, 2009 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 Link to comment Share on other sites More sharing options...
99ojo Posted February 4, 2009 Share Posted February 4, 2009 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 Link to comment Share on other sites More sharing options...
youknowwho4eva Posted February 4, 2009 Share Posted February 4, 2009 I just wanted to say hahahahahahaha passworts. Sorry I had to say it. Giggity Link to comment Share on other sites More sharing options...
James Posted February 4, 2009 Share Posted February 4, 2009 I just wanted to say hahahahahahaha passworts. Sorry I had to say it.Shutup.99ojo, good solution, I was thinking of using an array to explain it. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Andreik Posted February 4, 2009 Share Posted February 4, 2009 (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. expandcollapse popup$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 February 4, 2009 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now