Results 1 to 3 of 3

Thread: Deleting logs files which are one week old

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    This should give you a clue.... (note nobody flame me as it is just a quick knockup example)

    VB Code:
    1. Dim fsoMain As New FileSystemObject
    2. Dim oFile As File
    3. Dim oFileColl As Files
    4.  
    5. Private Sub Command1_Click()
    6.  
    7.     Set oFileColl = fsoMain.GetFolder("c:\winnt").Files
    8.        
    9.     For Each oFile In oFileColl
    10.         If oFile.DateLastModified <> Date Then
    11.             List1.AddItem oFile.Name
    12.         End If
    13.     Next oFile
    14.  
    15. End Sub
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    New Member
    Join Date
    Jun 2002
    Location
    Kuala Lumpur
    Posts
    2
    Hi guys,

    Thanks for all your help.

    I managed to do it and below is my script just
    to share with all of you. Again, thanks a lot, appreciates much.

    Dim objFSO, objTStream, s, fd, fd2, fd3

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set fd = objFSO.GetFolder("C:\dhl\DCS3.0\logs\")

    If fd.files.count > 0 Then

    For Each filesx in fd.files

    Set fd2 = objFSO.GetFile("C:\dhl\DCS3.0\logs\" & filesx.name)

    'Date - 1 day
    NewDate = DateAdd("d", -1, Date)

    s = fd2.DateCreated

    'Date for the File Created
    GetDay = DatePart("d", s)
    GetMonth = DatePart("m", s)
    GetYear = DatePart("yyyy", s)
    CreatedDate = DateSerial(GetYear, GetMonth, GetDay)

    If CreatedDate = NewDate Then

    fd2.Delete
    End If
    Next

    End If

  3. #3
    New Member
    Join Date
    Jun 2002
    Location
    Kuala Lumpur
    Posts
    2
    Hie guys n gals,

    Thanks for all the reply. Much appreciated. Below is my code just to share with all the gurus here. Kindly comment freely.

    Once again, many thanks to all of you.

    Rgds,
    andrewseah

    Dim objFSO, objTStream, s, fd, fd2, fd3

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set fd = objFSO.GetFolder("C:\dhl\DCS3.0\logs\")

    If fd.files.count > 0 Then

    For Each filesx in fd.files

    Set fd2 = objFSO.GetFile("C:\dhl\DCS3.0\logs\" & filesx.name)

    'Date - 1 day
    NewDate = DateAdd("d", -1, Date)

    s = fd2.DateCreated

    'Date for the File Created
    GetDay = DatePart("d", s)
    GetMonth = DatePart("m", s)
    GetYear = DatePart("yyyy", s)
    CreatedDate = DateSerial(GetYear, GetMonth, GetDay)

    If CreatedDate = NewDate Then

    fd2.Delete
    End If
    Next

    End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width