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:
Code:
If (InStr(ErrorCode,"already exists!")=0) AND (Len(ErrorCode)>0) AND (InStr(ErrorCode,"Invalid Offer!")=0) Then
'WRITING SOAPMessage to Text File so we can see what the error is
logfile.writeline OrderID & " - Unknown Error See Order Folder for Details"
strOutputFile2="C:/LogFiles/" & Cust & "/OrderFiles/"& OrderID &".txt"
'wscript.echo strOutputFile2
Dim OrderFSO, OrderFile
Set OrderFSO = CreateObject("Scripting.FileSystemObject")
Set OrderFile = OrderFSO.CreateTextFile(strOutputFile2, TRUE)
OrderFile.writeLine (SOAPMessage)
orderFile.writeLine "-----------------------"
OrderFile.writeLine "Response: " & xmlhttp.status
OrderFile.WriteLine xmlhttp.responseText
OrderFile.Close()
Set strOutputFile2 = nothing
Set OrderFile = Nothing
Set OrderFSO = Nothing
End If
End If
Can anyone see anything that would keep the txt file open even after the script is done executing?
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?
Re: File staying open after script executes
I have checked the file folder permissions about 100 times to make sure that is not the problem. The error line is here:
Set OrderFile = OrderFSO.CreateTextFile(strOutputFile2, TRUE)
If after the script bombs I try to move the file it creates there is an error saying that it can't be moved or modified as it is open by another program.
I've tried to figure this out and am completely lost.
Do you think this may have to do with the fact that I am not closing the script in the program? such as: Wscript.end
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?
Re: File staying open after script executes
I didn't program all of that so, I can't honestly tell you why there are forward slashes. LOL. I just noticed that as well...
That probably wouldn't have anything to do with the file permission issue would it? I don't think it would but it doesn't hurt to ask
Re: File staying open after script executes
Quote:
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?
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