Results 1 to 3 of 3

Thread: [RESOLVED] Deleting Old Text Files

  1. #1

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Resolved [RESOLVED] Deleting Old Text Files

    I have a program that generates a report, saves them to a directory (just in case), then emails it out to a specified list. What i'd like to do is delete the files that are more than a week or so old. I did some searching and found this script but i get an error.

    VB Code:
    1. Dim ofile As File
    2.     Dim ofolder As Folder
    3.     Dim ofso As FileSystemObject
    4.     Set ofso = New FileSystemObject
    5.     Set ofolder = ofso.GetFolder("C:\temp")
    6.     [hl=#FFFF99]For Each ofile In ofolder[/hl]
    7.         If DateDiff("d", ofile.DateCreated, Now) > 7 Then
    8.             If Mid(ofile.ShortName, InStrRev(ofile.ShortName, ".")) = ".txt" Then
    9.                 ofile.Delete False
    10.             End If
    11.         End If
    12.     Next
    13.        Set ofile = Nothing
    14.     Set ofolder = Nothing
    15.     Set ofso = Nothing

    The error i get is on the highlighted line. The Error i get is a message about object does not support this property or method.

    Thanks
    Andy
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Deleting Old Text Files

    You need to reference the Files collection of the Folder object.

    For Each ofile In ofolder.Files

  3. #3

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Deleting Old Text Files

    Thanks Bruce
    I should prolly read up on the filesystemobject, at least before i use it again
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

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