From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I loop a search algorithm to look for new files in a directory and store the file names in a string?

I'm not too familiar with the loops and am having trouble setting up this function.  Basically, I want the program to continually run, and as a file is placed/created in a certain directory, the program will take the file name and append it into a string array.

0 Kudos
Message 1 of 24
(3,864 Views)

You can do this in a couple of ways. You can poll or you can use the .NET FileSystemWatcher if you are on Windows. Using that method does not require polling. See this nugget for an example of using it.

=====================
LabVIEW 2012


Message 2 of 24
(3,863 Views)

Sorry, I'm not familiar with the .NET programming.  I'm still a beginner and getting to know the sub vi functions. 

0 Kudos
Message 3 of 24
(3,851 Views)

In that case it is very simple. There is a vi called list folder in the advanced file functions. It returns an array of filenames. Just run that periodically.

 

list folder.png

=====================
LabVIEW 2012


Message 4 of 24
(3,847 Views)

Ok, thanks, but the list folder vi in the advanced file functions returns the array of filenames sorted alphabetically.  I want to be able to track new files as they are added to the directory.  How much work is needed to strip the added filename from the 1D array and append it to a 1D array in memory - essentially creating a 1D array of filnames listed in the order that they were created/added to the directory?

 

I apologize in advance - my nested loop sorting skills are extremely rusty at this point.

0 Kudos
Message 5 of 24
(3,829 Views)

Directory Listing By Date.png

 

Here's a somewhat kludgy way of getting your directory listing by date.

Since List Folder also returns an entry for the folder itself, there will be one Empty entry in the Files list.

Message 6 of 24
(3,823 Views)

I usually use the .NET method myself, but if I were forced to poll I would do something like this.  I use a variant to hold the list of filenames.  I would only poll the folder info, when it has been modified then do the Folder List.  Any new files are spotted when the variant attribute does not exist (Replace = FALSE), and this is added to the array.

 

MonitorFolder.png

Message 7 of 24
(3,819 Views)

Could you please attach a VI for this example? Thanks!

0 Kudos
Message 8 of 24
(3,753 Views)

That is a VI snippet.  The VI is embedded in the image.  All you need to do is drag and drop the image from your browser to a block diagram.

0 Kudos
Message 9 of 24
(3,749 Views)

@Ravens Fan wrote:

That is a VI snippet.  The VI is embedded in the image.  All you need to do is drag and drop the image from your browser to a block diagram.


Does not work for me... LV 2009 SP1, MSIE.

0 Kudos
Message 10 of 24
(3,742 Views)