03-26-2013 07:00 AM
Hi everyone!
I'm a beginner with Labview and I'm doing my end of studies project. Here is my problem:
My app generates .doc files and I have to make sure that the app deletes oldest files once the free disk space falls below a set limit.
I've written some code that looks free disk space, which is compared to a value, the comparator output being connected to a Case Structure ...
Currently I have a list of all the file paths in my folder (using Recursive File List.vi). I found the function giving the last modified date of a file (using File/Directory Info).
But I don't find a loop sorting paths by date.
Thank you in advance ![]()
Solved! Go to Solution.
03-26-2013 08:24 AM
Bundle the timestamp with the path into a cluster, sort the array of clusters.
03-26-2013 08:32 AM
You don't really need to sort. Use a FOR loop to find which file is the oldest. Use a shift register to hold the oldest found date and another shift register to hold the index of the file with that date. Once you have the index, you can index out the file and delete it.
03-26-2013 11:03 AM - edited 03-26-2013 11:04 AM
Thank you both! ![]()
I understand why I don't need to sort but as a beginner, the solution of pcardinale help me.
I don't know how to "Use a shift register to hold the oldest found date and another shift register to hold the index of the file with that date." ![]()
Now I'm going to try to delete the oldest files with my sorted array.
03-26-2013 11:50 AM
Using the shift register method would allow you to delete the oldest file (just one) because it will only store the index of the oldest file. The sort method will allow you to utilize another for loop to delete say the oldest 10.
03-26-2013 11:53 AM
I actually agree that the sort is likely the better solution. It really depends on how many files you want to delete and how often, etc. But you can do more with the sorted array.
03-26-2013 01:48 PM
I don't really know now how many files I need to delete and how often...
Ok, I'm going to use the sort method in order to delete several files at once.
Thanks!
03-26-2013 02:38 PM
I'm not sure what variability in file size you would have, but deleting more than one would be a good idea.
Lets say you change what is included in the file and the new files are 20% larger than your old ones. If you only delete one at a time, you are going to run out of disk space eventually. You could also consider checking file size and make sure you delete enough files to make room for the new one.
Or an arbitrary number like 7 (i like this option better)
03-26-2013 03:37 PM
I think that I'm going to delete 25% of the files in the folder.
Thank you 🙂