I have a simple file watcher application which watches the folder C:\. I am watching the folder so that as soon as a new file is created in C:\, it moves the newfile to a specified folder somewhere else. My problem is that if two files are dropped in the C:\ folder at the same time, my code only deals with one of the files. I would like my code to identify both files, and move both of them.
Here's some of my code:
Dim folderToWatch As String = "C:\" PrvSubMain() watchFolder = New System.IO.FileSystemWatcher() watchFolder.Path = folderToWatch watchFolder.NotifyFilter = IO.NotifyFilters.FileName AddHandler watchFolder.Created, AddressOf FileCreated watchFolder.EnableRaisingEvents = True End Sub Private Sub FileCreated(ByVal source As Object, ByVal e As _ System.IO.FileSystemEventArgs) Dim fileName As String = "" Dim pathOfFile As String If e.ChangeType = IO.WatcherChangeTypes.Created Then fileName = e.Name End If pathOfFile = e.FullPath If fileName = "" = False Then 'Pass the pathOfFile and fileName off to the MoveFile function where it will move the file to another folder.. MoveFile(pathOfFile, fileName) watchFolder.EnableRaisingEvents = False End If End Sub
Thankyou in advance!