Posted 25 Feb 2021 Hello Guys, I would like to know if someone in here has made a VB script, there can delete files from the SD card in HMI? the reason why I ask, is I have some data logging on the HMI for our customer, but I would like the data logging to go in a loop so if the SD-card is full, it will delete the oldest file instead of stop data logging. who is there somebody there can show me an example on a VB for this :)? Share this post Link to post Share on other sites
Posted 25 Feb 2021 (edited) Here is a quick and dirty way to do it. Run it hourly as a scheduled event. Just change 6 to however many days you want to keep logs. 6 = 5 days, 23 = 22 days etc. You'll need to use this for every data set so if you have 3 data sets just cut and paste into 3 subroutines with the appropriate modifications to the directory. Every time you run it it deletes 1 folder only (if the folder is old enough) so if you have a massive backlog you need to delete I would do it manually first. Sub clearCard Dim List_Files As String() Dim i As Integer List_Files = System.IO.Directory.GetDirectories("\SDCard\Data Logging\Log Files\DataSet0") 'Change DataSet0 to whatever data set you need Array.Sort(List_Files) Array.Reverse(List_Files) 'This will sort so the most recent dates are at the start of the array i = List_Files.Length If i > 6 Then 'Change 6 to whatever value you desire. This is essentially how many days you keep files. 5 days = 6 System.IO.Directory.Delete(List_Files(6), True) End If End Sub Edited 25 Feb 2021 by photovoltaic clarity Share this post Link to post Share on other sites
Posted 15 Mar 2021 Thanks, @photovoltaic, I have one question about this. Do you write that I have to run I hourly? is it the subroutine or the datalog( I have attached a picture of where I think you mean I have to change it to hourly)? Right now when I run the code, I get this error: Quote IndexOutOfRangeException is thrown at clearCardFM01. E_SYS_999: IndexOutOFRangeException Share this post Link to post Share on other sites
Posted 15 Mar 2021 I will clarify a bit - so the folders that this macro looks at are the daily folders, you can have any setting in the update rate and "Start New Database File" section as long as you are saving the data at least once a day. Any longer than that and you need to make adjustments. I think your issue is from the Data Set name - in your multiview explorer under datalogging what did you name your dataset? To test this I would use a button to trigger the script at first. Check how many daily log folders are on your SD card before you do this and then run it say 5 times and then check to see there are 5 fewer folders. Once you confirm operation then have the macro run from global events as an hourly interval. Share this post Link to post Share on other sites
Posted 16 Mar 2021 Thanks, I will try to use the idea you came with, and add a button to trigger it :). The example I have shown it is named FM01, I have 6 different data set I have copied the code in for and I have modified the code to each dataset and set in different days they should delete here at the start. and it seems like I get the error when it is trying to delete the oldest file. but let me come back to you when I have tried with a button to trig the script :) Share this post Link to post Share on other sites
Posted 23 Mar 2021 Thanks again @photovoltaic, I got it to work :). I was wondering is their option or opportunity to access the SD card and see how much memory there's left on the card. and then remove using the instruction to delete files if we are running out of space :) Share this post Link to post Share on other sites
Posted 23 Mar 2021 I'm not aware of any, but I'm far from a VB whiz. Share this post Link to post Share on other sites