Solved

Deleting files in a single directory by their date

Posted on 2004-04-08
5
155 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 54
Sending a email via excel using vba 6 82
message box in access 4 46
Zip Folders Using Chilkat Routines 1 38
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

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