Solved

Deleting files in a single directory by their date

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

749 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