1

以下代码将从 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
4

2 回答 2

0

一旦启动它并等待它退出,您就可以将其process作为变量获取:

Dim theProcess As Process = Process.Start("F:\poop.bat")
theProcess.WaitForExit()
于 2013-04-14T19:31:07.210 回答
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()

...
于 2013-04-14T19:31:23.563 回答