?
Solved

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

Posted on 2014-04-11
3
Medium Priority
?
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

762 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