|
-
Jul 8th, 2005, 03:57 PM
#1
Thread Starter
Fanatic Member
[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:
Dim ofile As File
Dim ofolder As Folder
Dim ofso As FileSystemObject
Set ofso = New FileSystemObject
Set ofolder = ofso.GetFolder("C:\temp")
[hl=#FFFF99]For Each ofile In ofolder[/hl]
If DateDiff("d", ofile.DateCreated, Now) > 7 Then
If Mid(ofile.ShortName, InStrRev(ofile.ShortName, ".")) = ".txt" Then
ofile.Delete False
End If
End If
Next
Set ofile = Nothing
Set ofolder = Nothing
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
-
Jul 8th, 2005, 04:01 PM
#2
Re: Deleting Old Text Files
You need to reference the Files collection of the Folder object.
For Each ofile In ofolder.Files
-
Jul 8th, 2005, 04:12 PM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|