Jump to content

Maximum number of files open


Justin
 Share

Recommended Posts

I am creating a script to run in the background, and when a new file appears in a directory, it parses a text file to match the number in the filename with a corresponding number from the text file, renames the file, and moves it to another directory.

If the filename doesn't match any numbers in the text file, it moves the file to an 'error' directory.

When running my script i get the following error:

AutoIt Error
Line 0 (File "C:\...\brc_new.exe"):

$hFile = FileOpen($sFilePath,0)

Error: Unable to open file, the maximum number of open files has been exeeded.

Here is my script so far:

#include <File.au3>
#include <Date.au3>

Dim $aRecords
Dim $correctline
Dim $criFromfile

$timeScriptStart = _now()
FileWrite("program\timelog.txt","Program Started at " & _now()); initializes the time log file

While 1
    $brcNumber = 0;resets variable at the start of each loop
    $file = "";clears variable at the start of each loop
    $search = FileFindFirstFile("BRC\*.txt");looks for a text file in the BRC folder
    
    If $search = -1 Then;if no files are found, then...
    
    Else;if files are found then...
        
        $file = FileFindNextFile($search);set $file to the first listed file in the search
        $fileFullPath = "BRC\" & $file
        $brcNumber = StringLeft($file, 8); extracts Brc number from filename
        ConsoleWrite($brcNumber)        ; and send the number to the console
        
        If Not _FileReadToArray('cri.txt',$aRecords) Then                           ; Reads cri.txt and sends it 
            MsgBox(4096,"error"," Error reading log to Array       error:" & @error); to the array named $aRecords[].
            ExitLoop                                                                ; $aRecords[1] returns line 1 
        EndIf                                                                       ; of cri.txt
        
        For $x = 1 to $aRecords[0]; Read each line, do this each time
            $brcFromFile = StringTrimLeft($arecords[$x],9)
            If $brcFromFile = $brcNumber Then
                
                FileClose("cri.txt")
                ExitLoop
            Else
                FileClose("cri.txt")
                FileClose($fileFullPath)
                FileCopy ($fileFullPath,"BRC\error\" & $file)
                FileDelete($fileFullPath)
            EndIf
                            
        Next
        


    EndIf
    
        
    
    Sleep(15000)
WEnd

Any help?

Link to comment
Share on other sites

A maximum of 64 files may be opened at once I believe. I think what you are missing is a FileClose on your FileFindFirstFile. Add a FileClose($search) to your script.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Does this work?

#include <File.au3>
#include <Date.au3>

Dim $aRecords
Dim $correctline
Dim $criFromfile

$timeScriptStart = _now()
FileWrite("program\timelog.txt","Program Started at " & _now()); initializes the time log file

While 1
    $brcNumber = 0;resets variable at the start of each loop
    $file = "";clears variable at the start of each loop
    $search = FileFindFirstFile("BRC\*.txt");looks for a text file in the BRC folder
    
    If $search = -1 Then;if no files are found, then...
    
    Else;if files are found then...
        
        $file = FileFindNextFile($search);set $file to the first listed file in the search
        $fileFullPath = "BRC\" & $file
        $brcNumber = StringLeft($file, 8); extracts Brc number from filename
        ConsoleWrite($brcNumber)       ; and send the number to the console
        
        If Not _FileReadToArray('cri.txt',$aRecords) Then                          ; Reads cri.txt and sends it 
            MsgBox(4096,"error"," Error reading log to Array       error:" & @error); to the array named $aRecords[].
            ExitLoop                                                               ; $aRecords[1] returns line 1 
        EndIf                                                                       ; of cri.txt
        
        For $x = 1 to $aRecords[0]; Read each line, do this each time
            $brcFromFile = StringTrimLeft($arecords[$x],9)
            If $brcFromFile = $brcNumber Then
                
                FileClose("cri.txt")
                ExitLoop
            Else
                FileClose("cri.txt")
                FileClose($fileFullPath)
                FileCopy ($fileFullPath,"BRC\error\" & $file)
                FileDelete($fileFullPath)
            EndIf
                            
        Next
        

    FileClose ($file)
    EndIf
    
        
    
    Sleep(15000)
WEnd
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...