Causing a batch file to finish its operations, before continuing?

The following code will extract files modified today from the SourceDirectory and place them into the FilesExtracted folder, then the batch file will delete the rest of the files in the sourceDirectory. But after that is all done a brand new set of files will be copied from the OriginalTestFiles folder and put into the sourceDirectory, but its does not do it. Does anyone think that it could be because the batch files hasn't stopped its operations and is still deleting the files in the sourceDirectory, or is there another problem. Thank You all!

Imports System.IO

Public Class frmExtractionator

'  Dim txtFiles1 As Control
Dim sourceDirectory As String = "F:\CopierFolderforTestDriveCapstone"
Dim archiveDirectory As String = "F:\FilesExtracted"
Dim originalDirectory As String = "F:\OriginalTestFiles"

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click

    Try

        Dim txtFiles = Directory.EnumerateFiles(sourceDirectory)

        If (Not System.IO.Directory.Exists(archiveDirectory)) Then
            System.IO.Directory.CreateDirectory(archiveDirectory)
        End If


        For Each currentFileLoc As String In txtFiles

            Dim fileName = currentFileLoc.Substring(sourceDirectory.Length + 1)



            If (IO.File.GetLastWriteTime(currentFileLoc).ToString("MM/dd/yyyy") = DateTime.Now.ToString("MM/dd/yyyy")) Then
                MessageBox.Show(currentFileLoc & " moved", "Moved Succesfully")
                File.Move(currentFileLoc, Path.Combine(archiveDirectory, fileName))

            End If

        Next
    Catch eT As Exception
        Console.WriteLine(eT.Message)
    End Try

    System.Diagnostics.Process.Start("F:\poop.bat")


    Try
        Dim txtFiles2 = Directory.EnumerateFiles(originalDirectory)

        For Each currentFileLoc2 As String In txtFiles2

            Dim fileName = currentFileLoc2.Substring(originalDirectory.Length + 1)

            File.Move(currentFileLoc2, Path.Combine(sourceDirectory, fileName))

        Next
    Catch eT As Exception
        Console.WriteLine(eT.Message)
    End Try
End Sub

End Class

Answers


You can get the process as a variable once you start it and wait for it to exit:

Dim theProcess As Process = Process.Start("F:\poop.bat")
theProcess.WaitForExit()

Try monitoring the Process for completion...

'Start the process.
Dim Proc = Process.Start("F:\poop.bat")
'Wait for the window to finish loading.
Proc.WaitForInputIdle()
'Wait for the process to end.
Proc.WaitForExit()

...

Need Your Help

Mysqli and PDO combined with Javascript and Ajax… possible?

php ajax mysqli

Simple question from a noob programer. Thinking of several different styles and features to a project i have for a social website. question is this...

Get last MySQL binary log entry

mysql

I'm using MySQL replication, and I'd like a status script running on the slave to report the last statement that was replicated over to the slave.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.