steve8tch Posted December 10, 2003 Posted December 10, 2003 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
MattNis Posted December 10, 2003 Posted December 10, 2003 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]
Administrators Jon Posted December 10, 2003 Administrators Posted December 10, 2003 You can only close by filehandle. "c:\filename.txt" is probably classed as the number 0 which may by coincidence be the correct filehandle... Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
steve8tch Posted December 11, 2003 Author Posted December 11, 2003 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.
Administrators Jon Posted December 11, 2003 Administrators Posted December 11, 2003 There isn't a wildcard at the moment, might be worth considering. Also, when the script finishes all files are automatically closed, which is useful to know. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
MattNis Posted December 11, 2003 Posted December 11, 2003 (edited) 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 December 11, 2003 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]
Valik Posted December 11, 2003 Posted December 11, 2003 I never close by filehandle.....always by "c:\file.ext"and it always worksAs 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now