在继续之前导致批处理文件完成其操作?

时间:2013-04-14 19:23:19

标签: vb.net visual-studio-2010

以下代码将从SourceDirectory中提取今天修改的文件并将它们放入FilesExtracted文件夹,然后批处理文件将删除sourceDirectory中的其余文件。但是在完成所有操作之后,将从OriginalTestFiles文件夹中复制一组全新的文件并将其放入sourceDirectory,但它不会这样做。有没有人认为这可能是因为批处理文件尚未停止其操作并仍在删除sourceDirectory中的文件,或者是否存在其他问题。谢谢大家!

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

2 个答案:

答案 0 :(得分:0)

启动processwait for it to exit后,您可以将Dim theProcess As Process = Process.Start("F:\poop.bat") theProcess.WaitForExit() 作为变量:

{{1}}

答案 1 :(得分:0)

尝试监控流程以完成...

'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()

...