deef99 Posted October 15, 2009 Share Posted October 15, 2009 (edited) This script works except it ends. It will process 1 csv file...then the program quits. It does not sleep for 5 seconds and check for another csv file. What am I doing wrong? UPDATE: if no csv file exists, it stays live. If one does exist, it processes it THEN exits the program.#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Outfile=G:\CallCenter_downloads\TFN_Checker.exe#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#include "array.au3"#include "File.au3"#include "Date.au3"$file = ""$file1 = ""$dest = "\\files01\common\CallCenter_downloads\tfn_change.csv"$final = "\\files01\common\CallCenter_downloads\TFN Archive\"$logfile = ""$CountLines = 0If ProcessExists("asa.exe") Then ProcessClose("asa.exe")EndIfRun("C:\Program Files\Avaya\Site Administration\bin\ASA.exe")Sleep(3000)Send("^g")Sleep(2000);this will keep program running and checking for another file...While 9 = 9 ;look for first occurance of a file $search = FileFindFirstFile("\\files01\common\CallCenter_downloads\tfn_turndown\*.csv") While 1 ;look for additional files $file1 = FileFindNextFile($search) If @error Then ExitLoop ;MsgBox(0,"",$file&" "&$file1) FileCopy("\\files01\common\CallCenter_downloads\tfn_turndown\" & $file1, $dest, 1) ;FileDelete("\\files01\common\CallCenter_downloads\tfn_turndown\" & $file1) ;set the MM_YYYY for log file $tday = @MON & "_" & @YEAR ;open log file LogMM_DD.txt $logfile = FileOpen("\\files01\common\CallCenter_downloads\TFN_Log" & $tday & ".txt", 1) ;get the current hour and min $tCur = @MON & "/" & @MDAY & "," & @HOUR & ":" & @MIN & " - " $file = FileOpen("\\files01\common\CallCenter_downloads\tfn_change.csv", 0) ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop FileWrite($logfile, $tCur & $line & @CRLF) $array = StringSplit($line, ",") Select Case $array[4] = "U" $vec = 200 Case $array[4] = "D" $vec = 61 EndSelect ;set up correct Switch code for Product Select Case $array[3] = "gr_gt" $n = "IB " & $array[1] & " GR GT" Case $array[3] = "grc3" $n = "IB " & $array[1] & " GR MA" Case Else $n = $array[3] & " is not an Active Proj Code for " & $array[1] MsgBox(0, "case", $n) EndSelect ;Process this vdn now with ASA If StringLeft($n, 2) <> "IB" Then FileWrite($logfile, $tCur & $n & @CRLF) Else $f = "ch vdn " & $array[2] WinActivate("Avaya Site Administration") Send($f & "{ENTER}") Sleep(500) Send($n & "{ENTER}") Sleep(500) Send($vec & "{F3}") Sleep(1000) EndIf WEnd FileClose($file) FileCopy("\\files01\common\CallCenter_downloads\tfn_change.csv", "\\ardfiles01\common\CallCenter_downloads\TFN Archive\TFN_DONE" & @MDAY & @MSEC & ".csv", 1) FileClose($search) FileClose($logfile) WEnd Sleep(5000)WEnd Edited October 15, 2009 by deef99 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 15, 2009 Moderators Share Posted October 15, 2009 deef99,Your code:FileClose($file) FileCopy("\\files01\common\CallCenter_downloads\tfn_change.csv", "\\ardfiles01\common\CallCenter_downloads\TFN Archive\TFN_DONE" & @MDAY & @MSEC & ".csv", 1) FileClose($search) FileClose($logfile) WEnd Sleep(5000)My code:FileClose($file) FileCopy("\\files01\common\CallCenter_downloads\tfn_change.csv", "\\ardfiles01\common\CallCenter_downloads\TFN Archive\TFN_DONE" & @MDAY & @MSEC & ".csv", 1) FileClose($logfile) Sleep(5000) WEnd FileClose($search)You were closing the $search handle after the first file, so there were no more files to process.You also do not need the While 9 = 9 loop, unless you want to set up an infinite loop where you keep going through the files again and again!I have tested the loop (but not the code within it) and it works fine for me with a 5 sec gap between each file being dealt with just the once.M23P.S. It makes your code much easier to read if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 THANKS FOR THE SUPERFAST RESPONSE! Actually, I DO want an infinite loop so the program is always "live". Once I get it to stay running, I will move each csv file as it is processed until the folder is empty. deef99, Your code: FileClose($file) FileCopy("\\files01\common\CallCenter_downloads\tfn_change.csv", "\\ardfiles01\common\CallCenter_downloads\TFN Archive\TFN_DONE" & @MDAY & @MSEC & ".csv", 1) FileClose($search) FileClose($logfile) WEnd Sleep(5000) My code: FileClose($file) FileCopy("\\files01\common\CallCenter_downloads\tfn_change.csv", "\\ardfiles01\common\CallCenter_downloads\TFN Archive\TFN_DONE" & @MDAY & @MSEC & ".csv", 1) FileClose($logfile) Sleep(5000) WEnd FileClose($search) You were closing the $search handle after the first file, so there were no more files to process. You also do not need the While 9 = 9 loop, unless you want to set up an infinite loop where you keep going through the files again and again! I have tested the loop (but not the code within it) and it works fine for me with a 5 sec gap between each file being dealt with just the once. M23 P.S. It makes your code much easier to read if you use Code tags. Put [autoit ] before and [/autoit ] after your posted code (but omit the trailing space - it is only there so the tags display here). Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 (edited) Actually, I DO want an infinite loop so the program is always "live". Once I get it to stay running, I will move each csv file as it is processed until the folder is empty. No matter what, it gets to the third WHILE, runs out of lines to read in the csv file, then AutoIt shuts down. It will not stay up indefinitely, nor does it do any of the steps after the 1st WEnd. It's making me CRAZY!! Edited October 15, 2009 by deef99 Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 HAH! Yup, that runs indefinitely. Let me see if I can piecemeal the rest of my code in there... deef99, This is loop code that runs permanently for me. Change the FileFindFirstFile line and see if it runs permanently for you: ;this will keep program running and checking for another file... While 1 ;look for first occurance of a file $search = FileFindFirstFile("M:\Program\Au3 Scripts\*.au3");"\\files01\common\CallCenter_downloads\tfn_turndown\*.csv") While 1 ;look for additional files $file1 = FileFindNextFile($search) If @error Then ExitLoop ; Do stuff ConsoleWrite("Doing stuff to " & " - " & $file1 & @CRLF) Sleep(5000) WEnd FileClose($search) ConsoleWrite("Restarting loop" & @CRLF) WEnd Best to choose a folder with only a few files for the test! M23 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 15, 2009 Moderators Share Posted October 15, 2009 deef99,This code runs fine for me. Each found file ($file1) gets dealt with for the number of lines in $file and the whole thing repeats infinitely. Can you try it out and see? You will need to change the FileFindFirstFile and FileOpen lines first! ;this will keep program running and checking for another file... While 1 ;look for first occurance of a file $search = FileFindFirstFile("M:\Program\Au3 Scripts\*.au3") While 1 ;look for additional files $file1 = FileFindNextFile($search) If @error Then ExitLoop $file = FileOpen("M:\Program\Au3 Scripts\test.txt", 0) $iCount = 0 ; <<<<<<<<<<<<<<<<< check line ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $iCount += 1 ; <<<<<<<<<<<<<<<<< check line ConsoleWrite("Doing Stuff to "& " - " & $file1 & " - " & $iCount & @CRLF) ; <<<<<<<<<<<<<<<<< check line WEnd FileClose($file) Sleep(5000) WEnd FileClose($search) WEndM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 Ok...I am working on it now... deef99, This code runs fine for me. Each found file ($file1) gets dealt with for the number of lines in $file and the whole thing repeats infinitely. Can you try it out and see? You will need to change the FileFindFirstFile and FileOpen lines first! ;this will keep program running and checking for another file... While 1 ;look for first occurance of a file $search = FileFindFirstFile("M:\Program\Au3 Scripts\*.au3") While 1 ;look for additional files $file1 = FileFindNextFile($search) If @error Then ExitLoop $file = FileOpen("M:\Program\Au3 Scripts\test.txt", 0) $iCount = 0 ; <<<<<<<<<<<<<<<<< check line ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $iCount += 1 ; <<<<<<<<<<<<<<<<< check line ConsoleWrite("Doing Stuff to "& " - " & $file1 & " - " & $iCount & @CRLF) ; <<<<<<<<<<<<<<<<< check line WEnd FileClose($file) Sleep(5000) WEnd FileClose($search) WEnd M23 Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 (edited) This is what console write is giving me...i think cuz there is not a line 3 in the file so it's crashing? How to fix that then? this is test.csv: 8006189500,5890128,gr_dv,D 8009293823,5899275,gr_gt,D Doing stuff to - test.csv Doing Stuff to - test.csv - 1 Doing Stuff to - test.csv - 2 Doing Stuff to - test.csv - 3 I:\VB\TFN_Checker.au3 (59) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Case $array[4] = "U" Case ^ ERROR Edited October 15, 2009 by deef99 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 15, 2009 Moderators Share Posted October 15, 2009 deef99, i think cuz there is not a line 3 in the fileNo, it is because when you read the line, there are not enough comma-separated values to fill your array. You need to check if your array actually has those elements - something like this: $array = StringSplit($line, ",") If Not IsArray($array) Then ContinueLoop ; check if it is an array! If UBound($aArray) < 5 Then ContinueLoop ; check it has enough elements! Now if the elements do not exist, the script will just move onto the next line. M23 P.S. If you use the "Add Reply" button - it is about 1 cm below the "Reply" button you are using - you do not copy the previous post every time. It makes the topic easier to read and saves server space. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
deef99 Posted October 15, 2009 Author Share Posted October 15, 2009 AWESOME - IT'S WORKING NOW!!!!!!!!!!! THANK YOU FOR ALL YOUR HELP - especially for sticking in there and helping me resolve it fully!!!! I greatly appreciate you M23! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 15, 2009 Moderators Share Posted October 15, 2009 deef99, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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