07-28-2006 11:40 AM
07-28-2006 12:38 PM
07-28-2006 01:26 PM
There is indeed a .NET assembly which can be set to watch a directory for new files to appear. You can register for a .NET callback event if a file is created, renamed, deleted, etc. You can also explicitly set a filter to use. By that I mean you can set it to fire the event for only *.bmp files and not others. The .NET class in question is called FileSystemWatcher.
Take a look at the example below. Just enter in a path and a filter to use (such as *.txt or *.bmp), then run the example. Whenever you add a file to that folder that matches the filter, a string control value will update with the new file name. You will have to know something about .NET callback event handling and .NET use in general to use this in LabVIEW, but if you take the time to learn it, you'll get a much better solution than polling (which isn't a bad thing to fall back on either 🙂 ).
Here are some links on .NET and .NET events in LabVIEW. Hope this helps!
07-28-2006 02:26 PM
hi there
what about files copied to the directory when the LV-app is NOT running? can the .NET event handle the case when several files are copied to the directory at the same time while the processing of the first file is still going on? if this could be the case i'd choose pooling
07-28-2006 02:35 PM
.NET events registered by a LabVIEW VI can only be handled during run-time, just like any other events.You could of course create a service to run in the background running this .NET code. LabVIEW could then query the information from that service.
I don't see a particular need for that here. The best thing to do would be to poll once at the beginning for a first selection of files, then register the .NET event for all subsequent files.
I'm not terribly familiar with this class, so I'd refer you to the link above for the msdn website, but I'm pretty sure it can handle multiple files simultaneously. There are settings I didn't play with that allow for buffering of some sort. Have a look.
07-28-2006 03:12 PM
From the website linked above:
"The Windows operating system notifies your component of file changes in a buffer created by the FileSystemWatcher. If there are many changes in a short time, the buffer can overflow. This causes the component to lose track of changes in the directory, and it will only provide blanket notification. Increasing the size of the buffer with the InternalBufferSize property is expensive, as it comes from non-paged memory that cannot be swapped out to disk, so keep the buffer as small yet large enough to not miss any file change events."
Hope this helps!
02-22-2010 07:16 PM
hi, i met an problem when i use this method to watch a directory.
there is indeed an event when i copied a file to the watched dir. but if the file is too large, there is also an event then the file is not copied completely. then there will be an error if i read this file.
thanks!
02-23-2010 02:17 PM
02-23-2010 07:37 PM
Thanks for your reply!
An error with code 8 occurred when getting the file size during the copy operation. Is there any way to do this based on the file permission? Thanks again!