I originally posted in the asp.net forum and realized that this should probably be in this forum. Sorry for reposting here.
Original post - thread855-1450101
I have been away from this code for a few days. I am back working on this. I have tried a few different variations of the code below. I just can't seem to come up with a solution to only raise the change and create events once on a single file. In my searching on the web, this seems to be a common issue. I have not seen a true solution to this. Has anyone come across this.
Is there a way to check and see if a file has finished copying to a folder? It seems that when a file is copied to my watch directory, multiple events are raised during this process which triggers multiple attempts to copy my file.
Original post - thread855-1450101
I have been away from this code for a few days. I am back working on this. I have tried a few different variations of the code below. I just can't seem to come up with a solution to only raise the change and create events once on a single file. In my searching on the web, this seems to be a common issue. I have not seen a true solution to this. Has anyone come across this.
Is there a way to check and see if a file has finished copying to a folder? It seems that when a file is copied to my watch directory, multiple events are raised during this process which triggers multiple attempts to copy my file.
Code:
Public Sub StartWatcher()
Dim fwService As FileSystemWatcher
Dim gblpvFilters As String() = {"*.zip", "*.txt", "*.dat", "*.csv"}
For Each filter As String In gblpvFilters
fwService = New FileSystemWatcher()
fwService.Path = "C:\myFileWatcherTest\"
fwService.IncludeSubdirectories = True
'fwService.NotifyFilter = (NotifyFilters.LastWrite)
fwService.Filter = filter
AddHandler fwService.Changed, AddressOf MoveFile
AddHandler fwService.Created, AddressOf MoveFile
fwService.EnableRaisingEvents = True
Next
End Sub
Private Sub MoveFile(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
File.Copy(e.FullPath, "C:\move\" & e.Name, True)
End Sub
[\CODE]