LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger an event when a file is created.

Solved!
Go to solution

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!Smiley Happy

0 Kudos
Message 1 of 6
(4,688 Views)
Solution
Accepted by topic author JRRiquelme

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 6
(4,682 Views)

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.

Message 3 of 6
(4,672 Views)

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. 

 

Message 4 of 6
(4,658 Views)

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!Smiley Happy

0 Kudos
Message 5 of 6
(4,652 Views)

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.

Message 6 of 6
(4,610 Views)