I am using the FilesystemWatch er to look for files in a Directory, it does not matter what the file is. After a file appears it starts my ftp process and I end up with a bunch of 0 byte files because it processed before all the files arrived. I would like to WaitFor... (Files_Created) to finish but dont seem to have the right syntax to get this to work properly. I have working code up until it loops. As you can see I have tried various processes to get it to work... mostly commented out. I also have imported just about everything trying to get this to work. Please ask away. Thanks
Code:
Imports System Imports System.IO.File Imports System.IO Imports System.Threading Imports System.Collections Imports System.Collections.Specialized Imports System.Diagnostics Public Class FileSystemMonitor Public Shared Sub Main() Dim fsw As New FileSystemWatcher() ' create an object of FileSystemWatcher ' set properties of FileSystemWatcher object fsw.Path = "c:\Test" fsw.IncludeSubdirectories = True ' add event handlers AddHandler fsw.Created, New FileSystemEventHandler(AddressOf File_Created) fsw.EnableRaisingEvents = True ' enable monitoring Console.WriteLine("Started Monitoring WinServ Dir. Press enter key to stop.") Console.ReadLine() End Sub ' event handler to handle created event Public Shared Sub File_Created(ByVal obj As Object, ByVal e As FileSystemEventArgs) Dim fName As String = System.IO.Path.GetFileName(e.FullPath) 'file name with extension Dim newPath As String = "C:\Test" 'Newpath with no file Dim nPathAndFile As String = String.Concat(newPath, fName) 'Newpath with file and ext Dim S As New StringCollection() Dim T() As String = {nPathAndFile} Dim i As String Dim Count As Integer = 0 For Each i In T Count += 1 Dim di = New DirectoryInfo(newPath) Dim fi = di.GetFiles("*", SearchOption.AllDirectories) Console.WriteLine(fi.Length.ToString) ' & " " & nPathAndFile) Next 'If File.Exists(nPathAndFile) Then 'Console.WriteLine("Starting Transfer") 'Dim psi As New System.Diagnostics.ProcessStartInfo("C:\ftp2.bat") 'psi.RedirectStandardOutput = True 'psi.WindowStyle = ProcessWindowStyle.Hidden 'psi.UseShellExecute = False 'Dim ftp As System.Diagnostics.Process 'ftp = System.Diagnostics.Process.Start(psi) 'Dim myOutput As System.IO.StreamReader = ftp.StandardOutput 'Console.WriteLine(myOutput) 'ftp.WaitForExit(1000) 'If ftp.HasExited Then 'Console.WriteLine("Transfer Done") 'Dim s As String 'For Each s In System.IO.Directory.GetFiles("C:\Test") 'System.IO.File.Delete(s) 'Next s 'End If 'For Each i In T 'Delete(i) 'Thread.Sleep(2000) 'Next 'End If End Sub End Class 'Dim delt As New System.Diagnostics.ProcessStartInfo("C:\delt.bat") 'delt.RedirectStandardOutput = True 'delt.WindowStyle = ProcessWindowStyle.Hidden 'delt.UseShellExecute = False 'Dim delt2 As System.Diagnostics.Process 'delt2 = System.Diagnostics.Process.Start(delt)
Comment