Jump to content
Sign in to follow this  

fileopen issue

Recommended Posts

I just encountered an error in one of my scripts:

Line 0 (File "Y:\windows\Packages\AutoFLAC\autoflac_11\AutoFLAC.exe");
$new = fileopen($ripdir & "\" & $meta & $album & ".cue", 2)
Error: Unable to open file, the maximum number of open files has been exceeded.

Now, I know the error message is rather self-explanatory, but I can't figure out where the problem lies. I have several fileopen() and filefindfirstfile() calls in my script, but I just did a manual search through the entire program and I seem to close every one of them as soon as I'm done with the file handle.

Are there any other functions that require a fileclose()? Could this be that Windows itself can not open any additional files and it's not an issue with the script (unlikely, though, as I'm only running a couple other apps)? Any other ideas?

The program had been running for quite some time before I got the error message, making many iterations through the main body, so the behavior seems consistant with a simple leak. Like I said, though, I can't find that issue: I have 5 fileopen()'s, 3 filefindfirstfile()'s, and 8 fileclose()'s. What am I missing?

Thanks. I can complete the complete code if that'd help, but it's a pretty long script.

Share this post

Link to post
Share on other sites


Just attach the script and I'll do a quick check on your file handles and see if any are prone to be left open.


Share this post

Link to post
Share on other sites

Something just spotted here. You use Return to exit the function before FileClose can close the handle.

; Function to search %path% for executable
func SearchPath($file)
    ; Search DOS path directories
    $dir = stringsplit(envget("path"), ';')
    redim $dir[$dir[0]+1]
    $dir[$dir[0]] = @scriptdir
    for $i = 1 to $dir[0]
        $exefiles = filefindfirstfile($dir[$i] & "\*.exe")
        if $exefiles == -1 then continueloop
        $exename = filefindnextfile($exefiles)
            if $exename = $file then return 1 <------------ Problem here with handle left open
            $exename = filefindnextfile($exefiles)
        until @error
Edited by MHz

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...