Solved

Sub that deletes historical data (files) from a folder?

Posted on 2014-04-11
3
98 Views
Last Modified: 2014-06-10
I have some procedures that save files to a folder, that over time become pretty large.  Does any have a procedure that can manage the size of a folder based on a last modified date?  If the files are getting too old, or say today minus 30 days?  Delete any file that is older than 30 days?  Please advise and thanks. -R-
0
Comment
Question by:RWayneH
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39994274
Try this:
Sub TidyUpFolder()
    Dim sPath As String
    Dim sFileName As String
    Dim iDaysOld As Integer
    
    sPath = "C:\"   'path to files
    iDaysOld = 30   'number of days to keep
    
    If Right(sPath, 1) <> "\" Then sPath = sPath & "\"      'add backslash to path if missing
    sFileName = Dir(sPath & "*.*")
    
    Do While sFileName <> ""
        If FileDateTime(sPath & sFileName) < Date - iDaysOld Then
            Kill sPath & sFileName
        End If
        sFileName = Dir
    Loop

End Sub

Open in new window

Ron
0
 

Author Comment

by:RWayneH
ID: 40010261
Still testing this, sorry for the delay in response.
0
 

Author Closing Comment

by:RWayneH
ID: 40124355
Thanks for the  help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now