|
-
Aug 29th, 2005, 08:23 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Deleting files older than x [Resolved]
I have the following code:
VB Code:
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 0 To CInt(NUMFOLDERS)
While Dir(FARR(i) & "\*.BAK") <> ""
filespec = Dir(FARR(i) & "\*.BAK")
If filespec <> "" Then
Set f = fs.GetFile(FARR(i) & "\" & filespec)
mdate = f.DateLastModified
If mdate < DateAdd("d", -14, Format(Now, "mm/dd/yyyy")) Then
txtLog.Text = txtLog.Text & "delete: " & filespec & vbCrLf
End If
End If
Wend
Next
I'm just dumping the output to at textbox at the moment for testing, but the problem is that it never moves to the next file... it keeps running the same file in the while loop. Why doesn't it move to the next one?
Last edited by ober0330; Aug 29th, 2005 at 09:09 AM.
-
Aug 29th, 2005, 08:26 AM
#2
Fanatic Member
Re: Deleting files older than x
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Aug 29th, 2005, 08:27 AM
#3
Thread Starter
Frenzied Member
Re: Deleting files older than x
"i" is incremented in the for loop. I'm not worried about that. The Dir function is where my problem is.
-
Aug 29th, 2005, 08:30 AM
#4
Fanatic Member
Re: Deleting files older than x
Yeah i didn't see that for loop till i had already posted
How are you breaking the while loop?
Using VB6 or VB.net 2008 with .net 3.5
"Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad
-
Aug 29th, 2005, 08:32 AM
#5
Re: Deleting files older than x
The syntax looks about right. Try Dir$ instead.
-
Aug 29th, 2005, 08:32 AM
#6
Fanatic Member
Re: Deleting files older than x
If you use Dir() with a wild card, it will return the first matching file every time i.e. always the same file.
You need to call it repeatedly without any parameters to get subsequent files. After it has done the last one it will return null.
Try this:
VB Code:
Dim fs, f
Dim sFileName As String
Set fs = CreateObject("Scripting.FileSystemObject")
For i = 0 To CInt(NUMFOLDERS)
sFileName = Dir$(FARR(i) & "\*.BAK")
While sFileName <> ""
'Do what you need
sFileName = Dir$()
Wend
Next
Last edited by BrianHawley; Aug 29th, 2005 at 08:37 AM.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Aug 29th, 2005, 08:57 AM
#7
Thread Starter
Frenzied Member
Re: Deleting files older than x
Ahh... thanks Brian. That's kinda what I was thinking. It doesn't really matter anymore anyways, because what I was trying to do was keep my SQL Server backups deleted (< 2 or 3 weeks) and I figured out how to do it in my server maintenance plan.
Thanks anyways.
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
|