Re: FileSystemWatcher advice required please
- From: jimmyfishbean@xxxxxxxxxxx
- Date: 10 Feb 2006 05:59:35 -0800
Thanks for that Kevin. I have tried your suggestion.
However, if I drop more than 1 file into the DROP folders, only the
first file is passed to the OnChanged sub. Therefore I can only move 1
file (unless I call a sub that moves all files from the DROP folder to
a temp folder). Am I correct to assume that only 1 event is triggered
regardless of the number of files dropped into the directory? It would
be a lot easier/better if a separate event was triggered for each file.
If I try to move all files in the DROP folder in the OnChanged sub,
only 1 gets moved (as the application thinks that only one file is
there at the time the event was triggered). Do I need to use a timer
here to periodically check the fodler? I do not want to, and thought
the whole purpose of the filesystemwatcher was to provide functionality
that would allow each and every file droppped to trigger an event. I
take it I have it all so wrong...
My new OnChanged sub:
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As
System.IO.FileSystemEventArgs)
Dim intLastSlash As Integer = e.FullPath.LastIndexOf("\")
Dim strDir As String = Left(e.FullPath, intLastSlash)
Dim fso As New Scripting.FileSystemObject
Dim oFile As Scripting.File
Dim file As File
If Not e.Name = "XMLtoSOAP.ini" Then
If (File.GetAttributes(e.FullPath) And
FileAttributes.Directory) = FileAttributes.Directory Then
'Directory changed, created, or deleted.
Else
'File changed, created, or deleted.
'move the files to a temp location
If Not Directory.Exists(strDir & "\Temp") Then
Directory.CreateDirectory(strDir & "\Temp")
If File.Exists(strDir & "\Temp\" & e.Name) Then
file.Delete(strDir & "\Temp\" & e.Name)
End If
'now move the file(s)
For Each oFile In fso.GetFolder(strDir).Files
oFile.Move(strDir & "\Temp\" & e.Name)
Next
End If
End If
End If
End Sub
The problem is that I never know how many files will be dropped into
the DROP folder at one time. There may be just a single one, there may
be 20 and ther may be 20, followed by another 30 straight afterwards.
Thanks.
Jimmy
.
- Follow-Ups:
- Re: FileSystemWatcher advice required please
- From: Kevin Spencer
- Re: FileSystemWatcher advice required please
- From: jimmyfishbean
- Re: FileSystemWatcher advice required please
- References:
- FileSystemWatcher advice required please
- From: jimmyfishbean
- Re: FileSystemWatcher advice required please
- From: Kevin Spencer
- FileSystemWatcher advice required please
- Prev by Date: Re: HTTP/1.1 500 Server error
- Next by Date: RE: Web Service / Authenticating Proxy .NET and COM interop
- Previous by thread: Re: FileSystemWatcher advice required please
- Next by thread: Re: FileSystemWatcher advice required please
- Index(es):
Relevant Pages
|