Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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