kaibraine Posted October 20, 2006 Share Posted October 20, 2006 (edited) Ive written a simple script that reads a .txt file and inputs the hands into a 3rd party programme for me. it has been a learning experience for me as prior to this project I had no coding experience. the script works to process 1 file no problem, but I've been stuck for hours trying to figure out how to get it to open a new file once the loop is finished. I've been playig around with FileFindFirstFile, FileFindNextFile, _FileListtoArray but I just can't figure it out. My working script does the following......this is cut down of course. Dim $file = FileOpen("1.txt",0) ;mainloop While $file = 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop code Wend ;Functions How can i get it to open a new file once $line reaches @error -1 and repeat the main loop till all files in a specific directory have been processed? Edited October 20, 2006 by kaibraine Link to comment Share on other sites More sharing options...
JSThePatriot Posted October 20, 2006 Share Posted October 20, 2006 This should do the trick for you... Global $g_Dir = @MyDocumentsDir Func _ParseFilesDir($folName, $fileType = "*.*") FileChangeDir($g_Dir & "\" & $folName & "\") $search = FileFindFirstFile($fileType) If $search = -1 Then _ErrorMsg("No files/directories matched the search pattern") Return EndIf While 1 $found = FileFindNextFile($search) If @error Then ExitLoop $fileO = FileOpen($found, 0) While 1 $line = FileReadLine($fileO) If @error = -1 Then ExitLoop ;>>>>>>>>>>>>>>>>> ;YOUR CODE HERE!!! ;<<<<<<<<<<<<<<<<< WEnd FileClose($fileO) WEnd FileClose($search) EndFunc I hope it helps solve your issues. Please keep in mind that by default it calls "*.*" all files. You seem to need "*.txt" JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
kaibraine Posted October 20, 2006 Author Share Posted October 20, 2006 This should do the trick for you... Global $g_Dir = @MyDocumentsDir Func _ParseFilesDir($folName, $fileType = "*.*") FileChangeDir($g_Dir & "\" & $folName & "\") $search = FileFindFirstFile($fileType) If $search = -1 Then _ErrorMsg("No files/directories matched the search pattern") Return EndIf While 1 $found = FileFindNextFile($search) If @error Then ExitLoop $fileO = FileOpen($found, 0) While 1 $line = FileReadLine($fileO) If @error = -1 Then ExitLoop ;>>>>>>>>>>>>>>>>> ;YOUR CODE HERE!!! ;<<<<<<<<<<<<<<<<< WEnd FileClose($fileO) WEnd FileClose($search) EndFunc I hope it helps solve your issues. Please keep in mind that by default it calls "*.*" all files. You seem to need "*.txt" JS Looks like just what I need. Thanks so much. I have learned alot just by looking at the code. I'm gonna test it now. Link to comment Share on other sites More sharing options...
this-is-me Posted October 20, 2006 Share Posted October 20, 2006 Directly from the helpfile:$file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file)oÝ÷ Ø è¶«~º&¶¡zZ_WºÚ"µÍÈÚÝÜÈH[[[YÈÙ[[È[HÝ[XÝÜKÌÍÜÙXÚH[Q[Ý[J ][ÝÊ][ÝÊHÈÚXÚÈYHÙXÚØÈÝXØÙÜÙ[Y ÌÍÜÙXÚHLH[ÙÐÞ ][ÝÑÜ][ÝË ][ÝÓÈ[ËÙXÝÜYÈX]ÚYHÙXÚ]][ÝÊB^][YÚ[HB ÌÍÙ[HH[Q[^[J ÌÍÜÙXÚ HYÜ[^]ÛÜÙÐÞ M ][ÝÑ[N][ÝË ÌÍÙ[JBÑ[ÈÛÜÙHHÙXÚ[B[PÛÜÙJ ÌÍÜÙXÚTherefore, you need to look up FileReadLine and FileFindFirstFile in the help documentation and combine the two scripts together.Also, please take the time to read Support Forum FAQ Q1 regarding how to make your code readable during scripting. Who else would I be? Link to comment Share on other sites More sharing options...
kaibraine Posted October 20, 2006 Author Share Posted October 20, 2006 Directly from the helpfile: $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file)oÝ÷ Ø è¶«~º&¶¡zZ_WºÚ"µÍÈÚÝÜÈH[[[YÈÙ[[È[HÝ[XÝÜKÌÍÜÙXÚH[Q[Ý[J ][ÝÊ][ÝÊHÈÚXÚÈYHÙXÚØÈÝXØÙÜÙ[Y ÌÍÜÙXÚHLH[ÙÐÞ ][ÝÑÜ][ÝË ][ÝÓÈ[ËÙXÝÜYÈX]ÚYHÙXÚ]][ÝÊB^][YÚ[HB ÌÍÙ[HH[Q[^[J ÌÍÜÙXÚ HYÜ[^]ÛÜÙÐÞ M ][ÝÑ[N][ÝË ÌÍÙ[JBÑ[ÈÛÜÙHHÙXÚ[B[PÛÜÙJ ÌÍÜÙXÚ Therefore, you need to look up FileReadLine and FileFindFirstFile in the help documentation and combine the two scripts together. Also, please take the time to read Support Forum FAQ Q1 regarding how to make your code readable during scripting. Thx This is me. yes I have spent A LOOOONG time trying to combine these two things. FilereadLine I am comfortable with as it was the basis of the original script. please have patience with this noob Link to comment Share on other sites More sharing options...
this-is-me Posted October 20, 2006 Share Posted October 20, 2006 That's OK. After all this is a support forum. Who else would I be? 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