09-03-2013 11:22 AM
Hi!
I need labview to wait until a file is created in a certain folder (by other program) and then perform a task.
Is this possible?
I have no idea how to implement it.
Thank you!
Solved! Go to Solution.
09-03-2013 11:40 AM
Use the File/Directory Info function. Repeat every so often until you do not get an error.
I have also seen an example somewhere where somebody used .NET to get an event when a file was changed. I have no clue where it is or how it was done though.
09-03-2013 12:07 PM
File System Watcher does what you want if you don't want to poll.
I can't remember where I found this VI but attached is an example of it working.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-03-2013 12:58 PM
A different way of doing what crossrulz suggested is to poll the parent directory for the number of folders/files. Just use the "List Folder" VI and get the array size of the array of file/folder names.You can keep a running value of "past number of files/folders" and when that value is less than the new value, you know thta you have a new file/folder.
I don't know about the performance difference between this and checking for an error, but I usually don't like using errors for status.
09-03-2013 01:12 PM
Thank you both for your kind answers!
I´ll use the first one, the second one is causing my computer to freeze, i don´t know why.
Bye!
09-04-2013 05:57 PM
The File System Watcher is hanging there waiting for a new file to appear. To get it to finish executing, add a new file to the folder you've selected as an input. Notice in the attached image that you can set a timeout so if nothing happens you can continue executing your code. So you could use this in a polling fashion similar to listing the contents of the entire folder. Assuming you're writing an applicaiton specifically for Windows, I'd be inclined to use the File System Watcher because it's easier and (I suspect) more efficient. I haven't tested it, but I'd wager to say that when a folder has a lot of files in it, having to continually list the files and look for changes could become pretty slow and intensive.