LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get the last file in a folder

Hi,
I would like to read out the data from a spectrometer and plot them to a graph. Unfortunately I can do that just by reading out a "*.dat" file that the spectrometer software writes to a special folder. For this issue a function that reads out the last file in a folder would be very helpful (something like the CVI function GetFirstFile). Does anyone know if such a function exists, or how I could solve this problem in another way?
Thanks a lot,
best regards, Markus.
0 Kudos
Message 1 of 3
(3,309 Views)

Markus, how do you define the "last" file in the folder? The last recorded file or the last indexed file (supposing files are named for example as "ABCxxx.DAT" with xxx=progressive creation index)?

In either way, you can retrieve a list of files in at least two ways:

1. executing a loop with GetNextFile after the initial GetFirstFile. The problem is I don't know exactly which is the built-in order for these functions (creation date / access date, location on disk, name, other orders?) so you may need to scan all filenames listed and decide which one to consider

2. creating a list of filenames using DOS DIR command and scanning it. If the sorting algorithm is already included in the command, you can only retrieve the first element in the list and use it. As an example, to sort all *.DAT files in a folder, sorted by creation date from the most recend you can execute this command:  system ("dir /b c:\myFolder\*.dat /o:-d /t:c > output.txt"); reading next the first line of "output.txt" file that contains the filename only

There are several other sorting criteria built in DIR command: you can look at command help typing "help dir" at a command prompt



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,304 Views)


 


@Roberto Bozzolo wrote:

1. executing a loop with GetNextFile after the initial GetFirstFile. The problem is I don't know exactly which is the built-in order for these functions (creation date / access date, location on disk, name, other orders?) so you may need to scan all filenames listed and decide which one to consider


For each file that is found using GetFirstFile and GetNextFile, call the GetFileDate and GetFileTime functions. This way you can check which is the most recently created file.

0 Kudos
Message 3 of 3
(3,301 Views)