Jump to content

Reading files crashes at 510 files


Recommended Posts

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

#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

@bourny

Strange, i have cleaned your script and maybe this will work :D

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

  • Moderators

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! ;-)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 variable

Thanks

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...