Jump to content

Too many open files


Recommended Posts

I'm having trouble with one of my scripts. I'm hitting the open file limit, but I'm unable to see what I'm doing wrong.

The relevant bit of the script is:

$search = FileFindFirstFile("search_mdetails.asp*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files in directory")
    Exit
EndIf

While 1
         $file = FileFindNextFile($search) 
         If @error Then ExitLoop
         FileOpen($file,0)
         $filecontents = FileRead($file)
         FileClose($file)

<<do stuff with $filecontents>>

$output = FileOpen("output.csv",1)
FileWrite($output,$stuff)
FileClose($output)

WEnd

FileClose($search)

What have I missed?

Link to comment
Share on other sites

Your Posted code seems to be ok, the problem would appear to be

where you are processing the $filecontents,

post that section and may be able to help further.

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Your Posted code seems to be ok, the problem would appear to be

where you are processing the $filecontents,

post that section and may be able to help further.

HardCopy

If you really want it :)

$pos = StringInStr($filecontents,"<big>",0,2)
    $filecontents = StringTrimLeft ($filecontents, $pos+4)
    $pos = StringInStr($filecontents,"</big>",0,1)
    $company = StringLeft ($filecontents, $pos-1)
    $filecontents = StringTrimLeft ($filecontents, $pos)

    $pos = StringInStr($filecontents,"Address</td>",0,1)
    $filecontents = StringTrimLeft ($filecontents, $pos+57)
    $pos = StringInStr($filecontents,"<br>",0,1)
    $address1 = StringLeft ($filecontents, $pos-1)
    $filecontents = StringTrimLeft ($filecontents, $pos+3)

    $pos = StringInStr($filecontents,"<br>",0,1)
    $address2 = StringLeft ($filecontents, $pos-1)
    $filecontents = StringTrimLeft ($filecontents, $pos+3)

    $pos = StringInStr($filecontents,"</td>",0,1)
    $postcode = StringLeft ($filecontents, $pos-1)
    $filecontents = StringTrimLeft ($filecontents, $pos+4)

    $pos = StringInStr($filecontents,"Telephone</td>",0,1)
    $filecontents = StringTrimLeft ($filecontents, $pos+59)
    $pos = StringInStr($filecontents,"</td>",0,1)
    $phone = StringLeft ($filecontents, $pos-1)
    $filecontents = StringTrimLeft ($filecontents, $pos+4)

I don't think there's anything in there trying to open files.

Link to comment
Share on other sites

now what i see is your searching for

$search = FileFindFirstFile("search_mdetails.asp*.*")

but does .asp really have any other extension on the end?

The files are all in the form "search_mdetails.asp&id=0123456789ABCDEF.htm". You're right that the second wildcard isn't actually necessary, but removing it sadly doesn't afffect the files-open error :)
Link to comment
Share on other sites

I don't think there's anything in there trying to open files.

Indeed :)

Well using your original code, with the necessary changes - i read 10k+ image files

in a single directory

read the file

wrote the filename to an output file

with no errors.

Maybe someone else can see the problem, You got me stumped!

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

Are you using the latest beta?

If not download it and try it

I'm having trouble with one of my scripts. I'm hitting the open file limit, but I'm unable to see what I'm doing wrong.

The relevant bit of the script is:

$search = FileFindFirstFile("search_mdetails.asp*.*")

If $search = -1 Then
    MsgBox(0, "Error", "No files in directory")
    Exit
EndIf

While 1
         $file = FileFindNextFile($search) 
         If @error Then ExitLoop
         FileOpen($file,0)
         $filecontents = FileRead($file)
         FileClose($file)

<<do stuff with $filecontents>>

$output = FileOpen("output.csv",1)
FileWrite($output,$stuff)
FileClose($output)

WEnd

FileClose($search)

What have I missed?

Link to comment
Share on other sites

could you post the exact error message here. ur code seems fine, i also ran it with some modifications on a folder of over 5000 log files and it worked fine.

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

In the loop tho wouldnt that handle be the same as the one returned from FileFindNextFile() because they are both using the same file? Would FileOpen() make another instance of that file handle that also needs to be closed?

Would this work or would you still need to close 2 file handes since 2 are returned from the functions?

$file = FileOpen( FileFindNextFile($search), 0 )
         If @error Then ExitLoop
         $filecontents = FileRead($file)
         FileClose($file)

_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Link to comment
Share on other sites

FileOpen() returns a handle (which you do not record) that needs to be closed.

at the end you use FileOpen correctly... in the loop you do not.

Bingo! Thank you Larry.

Corrected code, for reference:

*snip*
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        $filehandle = FileOpen($file,0)
    $filecontents = FileRead($file)
        FileClose($filehandle)
*snip*
Link to comment
Share on other sites

Bingo! Thank you Larry.

Hmm, After chopping down some trees & seeing wood, makes sense now.

But, now im stumped why my trials didn't emulate smelly's error also.

HardCopy :)

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

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