• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

FileSystemWatcher - detecting a file created with no extension

Hello Experts,

I need to get FileSystemWatcher to detect the creation of a file that has no extension.  (Unfortunately, adding an extension isn't an option :(

I've tried setting the filter property to *filename, filename* and *filename* as well as just the name of just the file - with no joy.  I'm developing this in he .net 1.1 framework.  Anybody have any Ideas?  Here's the code I'm using:

...

                AddHandler fw.Created, New FileSystemEventHandler(AddressOf OnFileEvent)


                With fw
                    .Path = Me.GateWayPath
                    .Filter = "rcvmsg1"
                    .IncludeSubdirectories = False
                    .NotifyFilter = NotifyFilters.FileName
                    .EnableRaisingEvents = True
                    .WaitForChanged(WatcherChangeTypes.Created, Me.ReadTimeout * 60000)
                End With
...

0
xrvman
Asked:
xrvman
  • 3
1 Solution
 
ctm5Commented:
What sort of problem are you having? I don't see that the FileSystemWatcher depends on an extension at all. Are you looking for that specific file? If so, try leaving out the filter and then when you get the event, test for the filename you want.

ctm5
0
 
xrvmanAuthor Commented:
The problem I'm having with the filter is that it doesn't recognize the file being created.  So it basically waits the specified amount of time and returns with nothing. I did try leaving the filter off ("*.*" or empty string).  Had issues with that also.  Let me give you little more info on what's happening upstream of this code...

1. I write a temp file to a directory.
2 rename the file, so it not picked up (read and then deleted) prematurely by the another process that is looking for this file.
3. Then I wait for the file rcvmsg1 to be written to that same directory.

What happens in that scenario, is that step 1 and 2 are not complete by the time the event handler is created, so I pick up on the temp file creation.  I thought fine, I'll just loop thru each time the Create event fires and check the filename inside the event like this...

                AddHandler fw.Created, New FileSystemEventHandler(AddressOf OnFileEvent)



                Do While Len(JobID) = 0
                    '-- Setup FileWatcher to check for recieve file
                    With fw
                        .Path = Me.GateWayPath
                        .Filter = ""
                        .IncludeSubdirectories = False
                        .NotifyFilter = NotifyFilters.FileName
                        .EnableRaisingEvents = True
                        .WaitForChanged(WatcherChangeTypes.Created, Me.ReadTimeout * 60000)
                    End With
                Loop


... but that didn't work either.  It only picks up on the temp file being created... nothing after that.   Any suggestions on how I should be calling this?

Thanks
xrvman
0
 
ctm5Commented:
Set the timeout parameter to -1 to make it wait forever.
0
 
ctm5Commented:
TheLearnedOne,
Thank you for your work in cleaning up these abandoned questions.

ctm5
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now