Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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