LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching for unknown files based upon file name

Ok
 
I have a Labwindows / CVI requirement to search for a file based upon criteria in the file name.
 
To explain, the application is to log results to a file with the filename based upon dates.
 
So, I may have a Results file called "Results 01012001-.txt". The lack of end date means that the file is below a certain size and can be used for logging results. If the file becomes too large then the file can be closed by adding the end date to the name of the file, i.e. the file now becomes "Results 01012001-03052002.txt" as the file became too large on 3rd May 2002. A new file is then created called "Results 03052002-.txt etc. and so on. As time goes on the directory containing these files will grow as new files are created. The file name dates are dependant upon the size of the file and therefore how much testing is undertaken within the dates. Lots of testing means files with the start and end dates closer together and more files in the directory. Not a lot of testing means the dates in the file name being far apart.
 
The requirement here is to ensure that lots of small files, only containing a couple of results, are not created.
 
Now, in order for my application to find the correct file to log data to, I have to search and select the file without the end date. I can search for a file based upon the attributes of the file, i.e. hidden, read-only etc. by using GetFirstFile but this does not include searching for part of the file name. Other than reading in (by using GetFirstFile) and examining the file name of all files in a particular directory (could be quite a few) to see if it is in the correct file, how can this requirement be acheived intelligently, quickly and automatically without operator intervention.
 
Any help appreciated.
0 Kudos
Message 1 of 4
(3,287 Views)

Not sure if I have understood your problem - could you not simply use GetFirstFile () with a search name of "*-.txt"? (This function allows for wildcard characters; your incomplete filenames seem to always end with a "-" before the ".txt".)

JR

0 Kudos
Message 2 of 4
(3,269 Views)

Hi there,

Thanks for posting on the NI discussion forums.

I would concur with JR's suggested method here. It would seem that the naming of your files will tell you whether the file is 'complete' (of maximum size) or not by the fact the file name will end in '-.txt'.

As JR suggests, you will be able to find your desired file, i.e. the incomplete file, if you simply search for the file with the name ending in those characters. Please post back if you have any further issues.

Thanks,

National Instruments | Northern California
0 Kudos
Message 3 of 4
(3,229 Views)

Many thanks for your help. I have now used this information to create better structured code.

I am now find my way around CVI again since using Labview for a while.

0 Kudos
Message 4 of 4
(3,221 Views)