LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open Multiple .txt Files based on date

Solved!
Go to solution

I am attempting to build a VI that opens the last 5 production days of data in order to create a "real time" history graph that compares each day.

Production days are Monday 7 am through Saturday 7 am. Shifts are 1= 7-3, 2= 3-11, and 3=11-7.

I already built a VI that saves a shifts worth of OEE/Production values into a .txt file with a date and what shift it was. Example: dd/mm/yyyy_shift#.txt  (I am open to changing that format). 

 

I would like this VI to open all of the files for the previous 5 production days. I am having issues such as weekends or days when no production was planned (no file exists for that day). 

 

Thank you,

 

0 Kudos
Message 1 of 6
(3,714 Views)

I put this together in just a couple hours so it is a little messy. But it's the main idea for the data saving VI. From here I would like the Data Open VI to take the date here I changed it to %j for testing but %d%m%Y is what that normally is. Again thanks for looking into this. Data Save.png

0 Kudos
Message 2 of 6
(3,695 Views)

Hi engineer,

 

I am having issues such as weekends or days when no production was planned (no file exists for that day). 

What kind of issues?

When you know it is a weekend you only need to choose the next day. And you need to handle errors if the FileOpen function outputs them…

 

Other option:

Use ListFolder to get a list of all files fitting to your filename convention. Then parse the filenames and choose those ones fitting your "5 last days" requirement…

 

dd/mm/yyyy_shift#.txt  (I am open to changing that format).

I recommend not to put slashes in filenames. I also recommend to format the date like YYYYMMDD for easier sorting of the files…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 6
(3,689 Views)
Solution
Accepted by AUengineer

Hi Cory,

 

Once you have your list of files, you want the 5 most recent days. What I would do, is keep an array of the most recent days, and once you try to add the 6th one, stop looking through files. This assumes your array is sorted. I use a filename format like "YYYYMMDD_Filename.txt" most of the time, so that windows can easily organize by date. Here is an example to get you going:

Temp2.PNGTemp3.PNGTemp4.PNGTemp1.PNG

Message 4 of 6
(3,677 Views)

Hey Gregoryj,

 

Thank you for start on the file system. I do not want to manually input the file names of the most recent days. What would be a way to implement an array of saved files? I tried making that in the Data Save VI, but again I come across the issue of defining the previous 5 production days and whether or not all shifts were producing.

 

Thank you,

 

Cory

0 Kudos
Message 5 of 6
(3,621 Views)

Look for the List Folder function. 

0 Kudos
Message 6 of 6
(3,618 Views)