Solved

Deleting files in a single directory by their date

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now