Jump to content

Recommended Posts

If I define a UDF that opens a file, should I explicitly call the FileClose, or will AutoIt release it when the function ends? It is a local variable that holds the file pointer, but the helpfile says that the file is only released after the script exits. I would rather not leave the file handle open if it doesn't release it on the function's return.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to post
Share on other sites

Even though AutoIt does clean up after the programmer, it's bad habit to leave resources lying around if they aren't in use, so you should explicitly call FileClose().

And as a technical aside, the file handle is nothing more than an index into an array. So technically, if you know that there should be a valid file handle, you can pass a literal number as the "filehandle" parameter to reference it, completely skipping a variable (Note that I don't condone or advocate using this method).

Edit: Here is an example of that:

FileWrite("test.txt", "Blah")
FileOpen("test.txt", 0)
MsgBox(4096, "", FileReadLine(0))

The first file opened has a "handle" of 0, the second file is 1, et cetera (provided no files are closed, obviously, as that would free a handle up).

Edited by Valik
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...