Solved

Deleting files in a single directory by their date

Posted on 2004-04-08
5
159 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
[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
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
Suggested Courses
Course of the Month5 days, 8 hours left to enroll

626 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