Jump to content
Sign in to follow this  
bourny

Reading files crashes at 510 files

Recommended Posts

bourny

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

Share this post


Link to post
Share on other sites
FireFox

@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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

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._______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

 

Share this post


Link to post
Share on other sites
FireFox

@Melba23

Right, this may be a limit (limits sucks, but this is for avoid crashes :D )

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
bourny

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

Share this post


Link to post
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
Sign in to follow this  

×