2013-04-14 82 views
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 

回答

0

你可以得到process作爲變量,一旦你開始它和wait for it to exit

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

完美。解決了我的問題。非常感謝! –

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

... 
相關問題