bourny Posted June 19, 2009 Share Posted June 19, 2009 I am reading thru a load of files (1100 in total) looking for an email address in the "to" field of an eml file. This works fine but when it get to the 510th file it stops being able to open the files for reading ... I am totally confused as to why, here is my code expandcollapse popup#Include <File.au3> $ResultFile = "c:\StuckEmails\ScanResult.txt" $OpenResultFile = FileOpen($ResultFile, 1) $Count = 1 ; Check if file opened for reading OK If $OpenResultFile = -1 Then MsgBox(0, "Error", "c:\StuckEmails\ScanResult.txt") Exit EndIf $Msg = "Enter the recipient address that would be found in the TO: Field" & @lf & " This utility will scan all emails in the c:\stuckEmails\scan folder" Do $To = InputBox ( "Email Scanner", $msg , "" , "" , 300, 300) If @error = 1 then Exit Until $To <> "" ; Shows the filenames of all files in the current directory. If Not FileExists("c:\StuckEmails\ScanResult.txt") Then _FileCreate("c:\StuckEmails\ScanResult.txt") $search = FileFindFirstFile("c:\stuckEmails\scan\*.eml") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No .EML files matched the search pattern") Exit EndIf While 1 Sleep(500) $file = FileFindNextFile($search) If @error Then ExitLoop $Count = $Count + 1 TrayTip("Scanning .EML Files...#" & $Count , $File, 30, 17) $eml = FileOpen("c:\stuckEmails\scan\" & $file, 16) ; Check if file opened for reading OK If $eml = -1 Then TrayTip("FAILED TO OPEN # " & $Count , $File, 30, 17) Sleep(1000) FileWriteLine($OpenResultFile, "Failed To Open " & $File) Else ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($eml) If @error = -1 Then ExitLoop If $line = "" Then ContinueLoop Select Case StringInStr($Line, "to:" ) If StringInStr($Line, $To) Then msgbox(0, "", $line) FileWriteLine($OpenResultFile, $File) ExitLoop EndIf Case Else ContinueLoop EndSelect Wend FileClose($file) EndIf WEnd ; Close the search handle FileClose($search) FileClose($OpenResultFile) Sleep(5000) Exit Link to comment Share on other sites More sharing options...
FireFox Posted June 19, 2009 Share Posted June 19, 2009 @bourny Strange, i have cleaned your script and maybe this will work CODE #include <File.au3> Local $ResultFile = 'C:\StuckEmails\ScanResult.txt', $Count = 1 ; Check if file opened for reading OK If $OpenResultFile = -1 Then Exit MsgBox(16, 'Error', 'C:\StuckEmails\ScanResult.txt') $Msg = 'Enter the recipient address that would be found in the TO: Field' & @LF & ' This utility will scan all emails in the c:\stuckEmails\scan folder' While Not $To <> '' $To = InputBox('Email Scanner', $Msg, '', '', 300, 300) If @error = 1 Then Exit WEnd ; Shows the filenames of all files in the current directory. If Not FileExists('c:\StuckEmails\ScanResult.txt') Then _FileCreate('c:\StuckEmails\ScanResult.txt') $search = FileFindFirstFile('c:\stuckEmails\scan\*.eml') ; Check if the search was successful If $search = -1 Then Exit MsgBox(16, 'Error', 'No .EML files matched the search pattern') EndIf While Sleep(500) $file = FileFindNextFile($search) If @error Then ExitLoop $Count += 1 TrayTip('Scanning .EML files...#' & $Count, $file, 30, 17) $eml = FileOpen('C:\stuckEmails\scan\' & $file, 16) ; Check if file opened for reading OK If $eml = -1 Then TrayTip('FAILED TO OPEN # ' & $Count, $file, 30, 17) Sleep(1000) TrayTip('', '') FileWriteLine($ResultFile, 'Failed to Open ' & $file) Else ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($eml) If @error = -1 Then ExitLoop If $line = '' Then ContinueLoop Select Case StringInStr($line, 'to:') If StringInStr($line, $To) Then MsgBox(64, '', $line) FileWriteLine($ResultFile, $file) ExitLoop EndIf Case Else ContinueLoop EndSelect WEnd FileClose($file) EndIf WEnd ; Close the search handle FileClose($search) Exit Sleep(5000) Cheers, FireFox. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 19, 2009 Moderators Share Posted June 19, 2009 bourny,This a real WAG*, but 510 + FileOpen($ResultFile, 1) + FileFindFirstFile("c:\stuckEmails\scan\*.eml") = 512, which is the sort of nice round number that might well be the limit on open file handles for a process.I think that your FileClose($file) line should read FileClose($eml). At present I do not believe that you are closing the opened e-mail files!M23*WAG = Wild Ass Guess - not to be mistaken for a SWAG or Scientific Wild Ass Guess, which is just as unlikely, but expressed in rather more nerdish terms! ;-) 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...
FireFox Posted June 19, 2009 Share Posted June 19, 2009 @Melba23 Right, this may be a limit (limits sucks, but this is for avoid crashes ) Cheers, FireFox. Link to comment Share on other sites More sharing options...
bourny Posted June 19, 2009 Author Share Posted June 19, 2009 Well done Melba23 - I have indeed made a mess of the fileClose. It appears I changed the variable name on the fileopen and sorgot to change the close...Nice WAG@firefox - thanks for the reply.. The script cleaner appeared to clean more than just errors but lifted out bits of critical code - I put the code back in but made the same issue as Melba has pointed out I failed to change my fileclose variableThanks bourny,This a real WAG*, but 510 + FileOpen($ResultFile, 1) + FileFindFirstFile("c:\stuckEmails\scan\*.eml") = 512, which is the sort of nice round number that might well be the limit on open file handles for a process.I think that your FileClose($file) line should read FileClose($eml). At present I do not believe that you are closing the opened e-mail files!M23*WAG = Wild Ass Guess - not to be mistaken for a SWAG or Scientific Wild Ass Guess, which is just as unlikely, but expressed in rather more nerdish terms! ;-) 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