Jump to content

FileClose issues


 Share

Recommended Posts

I have a script that checks the status of PCs on our network. It reads PC names off a list and goes out onto the network to check them over.

Problem - too many open files.

Sometimes after 10 or 20 or 50 PCs the script will fail with a 'too many open files problem'.

I am reasonably sure that all my FileOpen( ) statments have a corresponding FileClose() statement.

A couple of questions.

Is there an editing tool to check for matching FileOpen( ) -FileClose( ) statements ?

Is there a statement / function that would hard close all open files - (so that everytime the script loops onto the next PC I could guarantee all file were closed - just in case there was some "leakage")

Thanks for any help

Link to comment
Share on other sites

you can close a file both by its filehandle and just by file name "c:\filename.txt"

after you close it, you can write a few lines of script that will attempt to read/write to that file. if it's unable to read/write then the file is closed.

[quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]

Link to comment
Share on other sites

oopps !

I found the error.

I had the following :

FileOpen()

If

....

Else

Loop Begin

Loop End

FileClose()

EndIf

I needed to move the FileClose to below the EndIf.

The If.. only happened very occasionally - that would explain why upto 50 PCs could be looked at before this error showed. This loop was nested inside another loop ....blah.. blah..excuse...excuse... :iamstupid:

Regarding the question I asked.

Is there a way of listing all 'open files' ?

Is there a 'wild card' way of closing all 'open files' ?

Thanks for your patients.

Link to comment
Share on other sites

I never close by filehandle.....always by "c:\file.ext"

and it always works

also....I haven't tested this lately.....but if a script crashes due to some syntax error, the files do not get automatically closed.

Edited by MattNis

[quote]I was busy waiting all night for the Columbus Day Bunny to come down my chimney and light fireworks in my pumpkin.There's so much wrong with that.Oh, I'm sorry, i forgot you were Jewish.[/quote]

Link to comment
Share on other sites

I never close by filehandle.....always by "c:\file.ext"

and it always works

As Jon said, "C:\file.ext" will resolve to 0. If you only have 1 file open at a time, that's fine, because the first file opened gets the handle 0. But if you open two files simultaneously, the second file will have the handle 1, and so trying to close by filename won't work for the second file, you'll just pass 0 which will either close the first file, or do nothing if the first file was already closed.
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...