Tsel Posted January 24, 2011 Share Posted January 24, 2011 Hi guys, Once again I need some help with finding my way. The script is a loop creating sessions on a server with the information the script gets from a couple of files. This has been working great except that now the files have gotten kind of big. Because of that I have to break up the creation of sessions in batches. The thing is that to separate the entries and to make sure I don't duplicate them I would have to create several different files and that would create a mess with the files. So I am right now limiting the sessions by making the loop in the script only run a set amount of times before pausing and waiting for me to tell it to continue or for the time out to run out for it to continue automatically. The thing I need help with is to be able to specify to the script on which entry in the file to begin so that in case I have to stop everything I don't start from the very beginning but specify how many lines to skip from the top of the files and lets say start on the 10th entry of the files. Can anyone help with that? I am guessing it would be the FileSetPos but not sure of how that would work. Will need that so I can put it on a msgbox where it would ask me for the number of lines to skip. Here is the script I am running. I know, a mess, but it is my first one and it is doing what I need it to do. However, comments and suggestions always welcomed. #include <Array.au3> Global $count = 40, $file_array[1] $file = FileOpen("c:\groupname.txt", 0) $files = FileOpen("c:\groupnumber.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf If $files = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Func login() ;this is to login to the server. Sleep(800) Send("username") Send("{ENTER}") Sleep(800) Send("password") Send("{ENTER}") Sleep(2000) Send("cd folder") Send("{ENTER}") Sleep(800) EndFunc ;==>login Func group() ; this give the session the group name I need to know what the session is about Sleep(1000) Send("^r") Sleep(900) WinActive("window") Send($lines) Sleep(800) Send("{ENTER}") WinActive("window") Sleep(500) EndFunc ;==>group Func name() ;this creates the session Sleep(800) Send("session -S " & $line) Send("{ENTER}") Sleep(800) EndFunc ;==>name Func looping() While $count <> 0 $lines = FileReadLine($files) $line = FileReadLine($file) If @error = -1 Then $file_array[0] = UBound($file_array) - 1 ExitLoop EndIf WinActive("window") Send("^u") Sleep(1000) WinActivate("window") Call("login") Call("group") Call("name") ;$count = $count - 1 _ArrayAdd($file_array, $line) _ArrayAdd($file_array, $lines) WEnd EndFunc While 1 $msg = MsgBox(36, "continue?", "Do you want to continue") If $msg = 6 Then WinActivate("window") WinClose("window") Sleep(200) WinActivate("Do you really want to quit") Sleep(200) Send("!y") WinActivate("Do you really want to close session") Sleep(200) Send("!y") Sleep(500) $count = 40 Sleep(800) Call("looping") Else FileClose($file) FileClose($files) _ArrayDisplay($file_array) Exit EndIf WEnd ------------------- Thanks a lot guys. Link to comment Share on other sites More sharing options...
Varian Posted January 24, 2011 Share Posted January 24, 2011 Not delving into your script, but rather answering the question, you can specify the line at which to start with FileReadLine() #include <File.au3> $File = @WindowsDir & '\win.ini' $Line_Number = Floor(_FileCountLines($File) /2) $Line = FileReadLine($File, $Line_Number) MsgBox(262208, 'Line', 'Total Lines ' & _FileCountLines($File) & @LF & 'Line Number ' & $Line_Number & @LF & $Line) Link to comment Share on other sites More sharing options...
wakillon Posted January 25, 2011 Share Posted January 25, 2011 (edited) Adapt this function To your needs ! #include <File.au3> _FileReadFromLineToLine ( @SystemDir & '\tcpmon.ini', 1001, 1005 ) Func _FileReadFromLineToLine ( $_FilePath, $_Start, $_End=0 ) Local $_Max = _FileCountLines ( $_FilePath ) If $_End=0 Or $_End > $_Max Then $_End = $_Max If $_Start > $_End Or $_End < $_Start Then Return -1 For $_I = $_Start To $_End ConsoleWrite ( '-->-- $_Line N°' & $_I & ' : ' & FileReadLine ( $_FilePath, $_I ) & @CRLF ) Next EndFunc ;==> _FileReadFromLineToLine ( ) Edited January 25, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts 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