LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to iterate through files in a directory in real time?

I have a program where users can write RPN equations into txt files so that the number and type of equations are completely customizable at run time.  I need to be able to iterate through .txt files in an Equations folder to load the equations into memory.  How can I do this in real time?

 

I know I could make the files eq 1.txt through eq 2.txt and iterate through until one doesn't exist, but my standard method has been to name the filename the same as the equation name.  Either way works.

 

Thank you.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 8
(5,004 Views)

First idea: Use the Windows API functions FindFirstFile()/ FindNextFile(). More info on MSDN.

0 Kudos
Message 2 of 8
(4,974 Views)

Hi Michael,

 

You could also use the GetFirstFile and GetNextFile functions that come built into CVI. These functions should allow you to iterate through the files in a directory.

 

GetFirstFile: http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/libref/cvigetfirstfile/

 

GetNextFile: http://zone.ni.com/reference/en-XX/help/370051Y-01/cvi/libref/cvigetnextfile/

 

Hope this helps,

 

Kevin

0 Kudos
Message 3 of 8
(4,955 Views)

FindFirst isn't supported in the RTOS.

 

I just tried GetFirst and it pops up. 

 

Thanks!

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 4 of 8
(4,952 Views)

GetFirst File is not supported in CVI Real Time.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 5 of 8
(4,931 Views)

Looking through the RT Utility Library I don't see any corresponding functions for GetFirstFile, you may be limited to just naming the files as you mentioned in your original post. Sorry.

 

-Kevin

0 Kudos
Message 6 of 8
(4,907 Views)

That is what I did.  I name the files Equation 0.txt through Equation n-1.txt and use GetFileInfo to check if they exist.  I put the equation name at the top of the text file whereas I used to get it from the file name.

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 7 of 8
(4,889 Views)

The RT OS is Posix-based, right ? (I may be wrong, I tested it years ago). If so, does it provide you with standard POSIX library ? In that case you may want to use dnotify() to know when files are added/removed from the directory you are monitoring.

<P>

Another solution would be to have a list file that lists all the files that sould be used. This way you iterate quicker and you can also enable/diable files quickly instead of having to rewrite/delete/move them.

0 Kudos
Message 8 of 8
(4,868 Views)