Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File locking and waiting

Status
Not open for further replies.

SpiderFlight

Programmer
Aug 22, 2001
37
US
I hope I have the right forum for this question. I have a VBscript that is called from a VB app. The VBscript opens and writes/appends the data to a file. My issue is the vbscript is executed many times within a loop and sends the output to a file, however I receive permission denied errors to the file. I suspect this is because the file is opened for output the first time and hasn't yet finished before the next iteration of the loop calls the vbscript again and tries to write/append data to the same file. Is there a way to have either the vbscript or vb6 app. wait until the file is available for writing? Below is the vbscript code that is executed for your reference.

Set fso = CreateObject("Scripting.FileSystemObject")
Set fileInput = fso_OpenTextFile(txtInputFile, ForReading, True)
If not flagAppend Then
Set fileOutput = fso_OpenTextFile(txtOutputFile, ForWriting, True)
Else
Set fileOutput = fso_OpenTextFile(txtOutputFile, ForAppending, True)
End If

TIA
 
As you'll see in the code below your suggestion won't work is this situation because the files that will be read are lised in the array, processed and then written to a output file. All files processed will be written to this output file.

Here is the code.
------- VB6 Application
Const cstrPPES_audit_ETL As String = """C:\Program Files\Cognos\Auditing\ppes_audit_ETL.vbs """
Const cstrPPES_audit_ETL_params As String = " -i " & """C:\Program Files\Cognos\cer3\ppserver\"
Const cstrCSVOutputFile As String = """ -O " & """C:\Program Files\Cognos\Auditing\ppes_audit_ETL_OUT.csv """ & " -Q "
.
.
.
For x = 1 To y
If ListofFiles(x) <> "" Then
If x <> 1 Then
sCommand = cstrPPES_audit_ETL_params & ListofFiles(x)
sCommand = sCommand & cstrCSVOutputFile & " -A"
Else
sCommand = cstrPPES_audit_ETL_params & ListofFiles(x)
sCommand = sCommand & cstrCSVOutputFile
End If

Call RunShellExecute("open", VBscript, sCommand, sWorkDir, SW_HIDE)

End If
Next x

----- VBscript
.
.
.
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileInput = fso_OpenTextFile(txtInputFile, ForReading, True)
If not flagAppend Then
Set fileOutput = fso_OpenTextFile(txtOutputFile, ForWriting, True)
Else
Set fileOutput = fso_OpenTextFile(txtOutputFile, ForAppending, True)
End If

The error is flagged on the statement Set fileOutput = fso_OpenTextFile(txtOutputFile, ForAppending, True)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top