LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete old files to free up HD Space

Solved!
Go to solution

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 Smiley Happy

0 Kudos
Message 1 of 9
(4,761 Views)
Solution
Accepted by topic author rafale350

Bundle the timestamp with the path into a cluster, sort the array of clusters.

Captured001.png

Message 2 of 9
(4,726 Views)

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 9
(4,723 Views)

Thank you both! Smiley Happy

 

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." Smiley Frustrated

 

Now I'm going to try to delete the oldest files with my sorted array.

 

0 Kudos
Message 4 of 9
(4,695 Views)

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.

 

Message 5 of 9
(4,681 Views)

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 9
(4,677 Views)

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!

0 Kudos
Message 7 of 9
(4,654 Views)

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)

0 Kudos
Message 8 of 9
(4,649 Views)

I think that I'm going to delete 25% of the files in the folder.

 

Thank you 🙂

0 Kudos
Message 9 of 9
(4,637 Views)