Re: FileSystemWatcher advice required please

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Re: FileSystemWatcher advice required please
    ... Why are you using OnChange? ... file (unless I call a sub that moves all files from the DROP folder to ... If I try to move all files in the DROP folder in the OnChanged sub, ... Dim strDir As String = Left ...
    (microsoft.public.dotnet.framework)
  • Re: Execute macro for all documents in the folder
    ... It is simple enough to batch process a single folder. ... Dim strFileName As String ... It seems as though the below macro from an earlier posting was put ...
    (microsoft.public.word.docmanagement)
  • Re: Execute macro for all documents in the folder
    ... It is simple enough to batch process a single folder. ... Dim strFileName As String ... It seems as though the below macro from an earlier posting was put ...
    (microsoft.public.word.docmanagement)
  • Re: HTML Item properties vs. Regular item properties
    ... I don't use the MSN provider, but AFAIK the date in the default store's is ... OutlookSpy - Outlook, CDO ... as well as the Sent Items folder on the MSN server. ... Dim app As Outlook.Application ...
    (microsoft.public.outlook.program_vba)
  • Re: HTML Item properties vs. Regular item properties
    ... Why would Outlook record different times for the HTTP ... and the default folder? ... Dim app As Outlook.Application ... "Dmitry Streblechenko" wrote: ...
    (microsoft.public.outlook.program_vba)