LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete files older than time period

Solved!
Go to solution

I have a sub vi (attached) which I runs after a time period checks files and comapres them against a time constraint. If that time constraint is met the the files are either deleted or moved. My current setup uses the file/directory info vi to check the folder path. I want to delete or copy the files after a time period. Given the last modification output on the file/directory info this only checks the last modified date of the folder and I want it to check the files in the folder. How would I do this?

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 1 of 11
(6,091 Views)

Hi Paul,

 

this function will also give your the modification date of the file - when you provide the full path of the file!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(6,085 Views)

Hi GerdW,

 

Thanks for the reply, I need to specify the folder because I want the application to delete the contents of the folder that are older than a time period

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 3 of 11
(6,080 Views)

Hi Paul,

 

is there any problem in using the ListFolder function?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(6,075 Views)

The ListFolder function lists out all the files as expected.

 

I can get all the timestamps out given the attached method but how do I work that into my code?

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 5 of 11
(6,071 Views)

Hi Paul,

 

I can't open your Vi right now, but I guess you only need to compare the modifiction date with your threshold value…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 11
(6,052 Views)

Hi Paul,

 

now I took a look into your VI:

You already know how to create a full path of those files using BuildPath in the inner case structure.

You just need to do the same when you want to check the mod date of your file (instead of the folder path)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 11
(6,034 Views)

I'm trying to do a same thing.

 

Did you ever find a solution to this?

Looks like the method for your if statement is working correctly.  But you're using the same path into your case structure. That includes every file in that directory. Not only the old ones.

Somehow you need to SELECT the old files based on last modification date.

 

I was thinking about opening a cmd window and performing the task outside of labview! Basically write the file names to a text file and read from that to select your old files. Any better ideas using labview functions?

0 Kudos
Message 8 of 11
(5,825 Views)
Solution
Accepted by topic author PauldePaor

Hi CAEHP

 

I did eventually get it working. I have attached the entire finished program. Feel free to use it and change it around to suit your needs. The finished application will only delete or move the files in the specified folder(s) older than the set time. You can also set how often you want the application to check the folder(s).

 

Hope this helps Smiley Happy

----------------------------------------------------------------------------------
I have not lost my mind, it's backed up on a disk somewhere
0 Kudos
Message 9 of 11
(5,812 Views)

Hi Paul,

 

I think I could use this application for my interest but one of the subvi is missing, named File Time Date?

Can you please add that to the zip folder if possible? Thanks

 

Jatin

0 Kudos
Message 10 of 11
(4,344 Views)