Solved

Deleting files in a single directory by their date

Posted on 2004-04-08
5
156 Views
Last Modified: 2010-05-02
How do I delete files from a specific directory that are older than 30 days?  I'm currently unable to browse this directory because it's size is almost 5Gb and the WinNT Server 4's browser stops responding when I try to view its contents.
0
Comment
Question by:HarmonicMinor
  • 3
5 Comments
 
LVL 7

Expert Comment

by:ramesh12
ID: 10788292
Did you try deleting them using command line
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 200 total points
ID: 10788724
Private Sub Form_Load()
    Call DeleteFiles("C:\MyFolder\", 30)
End Sub
Private Sub DeleteFiles(ByVal sFolder As String, iDays As Integer)
    Dim sFile As String, dDateCheck As Date
    dDateCheck = Now
    sFile = Dir(sFolder, vbNormal)
    Do Until sFile = vbNullString
        If DateDiff("d", dDateCheck, FileDateTime(sFolder & sFile)) <= -iDays Then
            MsgBox "Last Modified:" & vbCrLf & vbCrLf & FileDateTime(sFolder & sFile), , sFile
            'Call Kill(sFolder & sFile) '<-- will delete file.. uncomment to try
        End If
        sFile = Dir
        DoEvents
    Loop
End Sub
0
 

Author Comment

by:HarmonicMinor
ID: 10788732
Deleting a specific range of files from a command prompt?  If the size of this directory wasn't so huge, it'd be easy to use XCOPY /D:3-08-04 to copy the files I want to keep and simply kill the directory contents.   I used this before in VB programs with much smaller directories.   Unfortunately, the server becomes unstable when simply accessing this directory.
0
 

Author Comment

by:HarmonicMinor
ID: 10788743
zzzz', looks interesting.

I used DateDiff in the past and that looks like, if it's older than 30 days....goodbye!

I'll test it tomorrow morning.

Thx!
0
 

Author Comment

by:HarmonicMinor
ID: 10792537
With some modifications, your code did what I wanted.

Thanks !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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