Solved

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

Posted on 2014-04-11
3
100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

932 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

15 Experts available now in Live!

Get 1:1 Help Now