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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FilsSystemObject not finding file that is clearly there.

Status
Not open for further replies.

cdck

Programmer
Nov 25, 2003
281
US
I have a program which creates a batch file, runs it, and then manipulates the files the batch file causes to be output. When it gets to the point where it's supposed to open and manipulate those files, it gives me an error telling me that the first file does not exist. If I navigate to the folder in which the file should be found (In this case, C:\ECDIS\FULLtest\PROC\OUTDB.txt) the file is sitting right there.

Can anyone see the problem with the code below? I start at the point where the batch file is created and then run, and end on the line which throws the error.

Code:
        'Create the batch file to process the data and then run it.
        Dim BatFile
        Dim BasePath As String = Me.lblRoot.Text & "ECDIS\"

        If Not objFSO.FileExists(Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\BATCH.bat") Then
            BatFile = objFSO.CreateTextFile(Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\BATCH.bat")
        Else
            objFSO.DeleteFile(Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\BATCH.bat")
            BatFile = objFSO.CreateTextFile(Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\BATCH.bat")
        End If

        Dim strBatLine As String = ""

        strBatLine = "PATH " & Me.lblRoot.Text & "ECDIS\CIE2RGB\"
        BatFile.WriteLine(strBatLine)

        strBatLine = Me.lblRoot.Text
        BatFile.WriteLine(strBatLine)

        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psdb.dai DAY_BRIGHT " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outdb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psdbb.dai DAY_BLACKBACK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outdbb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psdwb.dai DAY_WHITEBACK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outdwb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psd.dai DUSK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outd.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.u -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psn.dai NIGHT " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outn.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.n -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psnr.dai NIGHT_RED " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outnr.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.n -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvdb.dai DAY_BRIGHT " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvdb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvdbb.dai DAY_BLACKBACK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvdbb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvdwb.dai DAY_WHITEBACK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvdwb.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.d -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvd.dai DUSK " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvd.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.u -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvn.dai NIGHT " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvn.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.n -s 31"
        BatFile.WriteLine(strBatLine)
        strBatLine = Me.lblRoot.Text & "ECDIS\CIE2RGB\cie2rgb " & Me.lblRoot.Text & "ECDIS\CIE2RGB\psvnr.dai NIGHT_RED " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\PROC\outvnr.txt -i " & Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\data.n -s 31"
        BatFile.WriteLine(strBatLine)


        BatFile.Close()

        'Here's where it fires.
        System.Diagnostics.Process.Start(Me.lblRoot.Text & "ECDIS\" & Me.txtSN.Text & "\RAW\BATCH.bat")




        'Check that the proc and final paths do not exist; 
        'Create the final folder if it doesn't; stop the process if the PROC doesn't.
        If Not objFSO.FolderExists(strProcPath) Then
            MessageBox.Show("There are no files to process for this Serial Number.")
            Exit Sub
        End If

        If Not objFSO.FolderExists(strFinalPath) Then
            objFSO.CreateFolder(strFinalPath)
        End If

        'File to use for the 3P4 output
        'Check that the file does not exist; delete it if it does.
        If objFSO.FileExists(Me.lblRoot.Text & "ECDIS\" & strSN & "\FINAL\Mon_3P4.dat") Then
           objFSO.DeleteFile(Me.lblRoot.Text & "ECDIS\" & strSN & "\FINAL\Mon_3P4.dat")
        End If

        'File to use for the VM 3P4 output
        'Check that the file does not exist; delete it if it does.
        If objFSO.FileExists(Me.lblRoot.Text & "ECDIS\" & strSN & "\FINAL\Mon_VM_3P4.dat") Then
            objFSO.DeleteFile(Me.lblRoot.Text & "ECDIS\" & strSN & "\FINAL\Mon_VM_3P4.dat")
        End If


        'The specific file name sought will change based on the iteration.  
        'intWazzup tracks how many iterations we've done, strWhich is set based on intWazzup
        Dim intWazzup As Integer = 1
        Dim strWhich As String = ""
        Const ForReading As Integer = 1

        Dim objOutputECDIS, objIn
        objOutputECDIS = objFSO.CreateTextFile(Me.lblRoot.Text & "ECDIS\" & strSN & "\FINAL\Mon_3P4.dat")

        objIn = objFSO.OpenTextFile(strProcPath & "MonTops.dat", ForReading)

        strText = objIn.ReadAll
        objIn.Close()
        objOutputECDIS.WriteLine(strText)

        'Run iterations for the first set
        Do Until intWazzup = 7
            Select Case intWazzup
                Case 1
                    strWhich = "OUTDB.TXT"
                Case 2
                    strWhich = "OUTDBB.TXT"
                Case 3
                    strWhich = "OUTDWB.TXT"
                Case 4
                    strWhich = "OUTD.TXT"
                Case 5
                    strWhich = "OUTN.TXT"
                Case 6
                    strWhich = "OUTNR.TXT"
            End Select

            'Open the file to add from and read contents to a variable - then write it in
            objIn = objFSO.OpenTextFile(strProcPath & strWhich, ForReading)

Cheryl dc Kern
 
More info:

If I run the same process a second time without deleting the files the first pass created, it finds them and processes them without error.

If I go back and delete those files and try again - error again.

Cheryl dc Kern
 
Ignore this thread. I added a 1-second wait after the batch file runs before it continues the process, and now it fires fine. Apparently things were just moving too fast for the system to give accurate information.

Cheryl dc Kern
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top