nbrege Posted January 24, 2006 Posted January 24, 2006 I am writing a program that watches a certain folder for incoming files & then moves those files to another folder. Here's the problem: if I copy a group of files into the watched folder it works fine, but if I move a group of files into the watched folder it doesn't do anything, the event handler never triggers. What is the proper notify filter to use to watch for new files in a folder? I have tried both the Size & LastWrite filters but neither does what I want. Any help would be appreciated. Here is the code I have so far: Imports System.IO Imports System.Diagnostics Public Class Form1 Const watchfolder As String = "c:\checked" Const targetfolder As String = "c:\checked2" Dim fsw As New FileSystemWatcher(watchfolder) Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Watch for changes in folder size fsw.NotifyFilter = (NotifyFilters.LastWrite) ' Register a handler that gets called when a file is created, changed, or deleted. AddHandler fsw.Changed, New FileSystemEventHandler(AddressOf OnChanged) ' Begin watching. fsw.EnableRaisingEvents = True End Sub Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs) ' folder contents have changed Console.Beep() ' Create a reference to the current directory. Dim di As New DirectoryInfo(watchfolder) ' Create an array representing the files in the current directory. Dim fi As FileInfo() = di.GetFiles() Console.WriteLine("The following files exist in the current directory:") ' Print out the names of the files in the current directory. Dim fiTemp As FileInfo For Each fiTemp In fi Console.WriteLine(fiTemp.Name) My.Computer.FileSystem.MoveFile(watchfolder & "\" & fiTemp.Name, targetfolder & "\" & fiTemp.Name, True) Next fiTemp End Sub Thanks... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.