If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

File staying open after script executes

I have a script that will fire once an hour. In this script txt files are created. The next time the script fires, it may or may not create another file (with the same name). However I am getting an permission denied error. I believe this to be because the original file is still open even though the script has finished executing. I can't figure out why the txt file will still be open for editing when I have closed it and cleared out all of the variables from memory. Any help at all would be appreciated. My code for creating the file is below:

Re: File staying open after script executes

The issue may not have anything to do with the file being left open. After all, you did call the object's Close method before exiting the script. Have you checked the file's attributes (Read-only, etc.)? Where is the file being saved? In what line of the code are you getting the error?

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0

Re: File staying open after script executes

I don't think WScript.End will have any effect. The Close method and the destruction of the TextStream object should be sufficient.

If the file is always going to be overwritten, why not delete it first before re-creating it? Also, have you tried the OpenTextFile method?

BTW, is there any reason for using forward slashes in strOutputFile2?

Last edited by Bonnie West; Dec 4th, 2012 at 08:35 AM.

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0

Re: File staying open after script executes

Originally Posted by Dubya007

That probably wouldn't have anything to do with the file permission issue would it?

I don't know... Have you tried correcting it to backslashes?

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0

Re: File staying open after script executes

I actually found out what the problem was. We have another program that was monitoring the folders and opening files to read their contents and never closing them. I felt really stupid when I found that out. any way thanks for the help

Shawn

"...Men will still say THIS was our finest hour"
If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?