By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

Dynamically iterating through log files

P: n/a
It seems there has got to be a better way to work with log files where
I want to keep 8 days of logs. For instance if I wanted to keep 80
days, this would be a horrible approach. How can I make this more
dynamic and efficient?
Const FTPOutputFile = "output-files.log"
Const FTPOutputFile1 = "output-files-1.log"
Const FTPOutputFile2 = "output-files-2.log"
Const FTPOutputFile3 = "output-files-3.log"
Const FTPOutputFile4 = "output-files-4.log"
Const FTPOutputFile5 = "output-files-5.log"
Const FTPOutputFile6 = "output-files-6.log"
Const FTPOutputFile7 = "output-files-7.log"

Sub Main()
'Do Stuff - gather log information
If a new day
RotateLogFiles()
End if
'Write to log....
End Sub

Sub RotateLogFiles()

'Delete Oldest Log

If objFSO.FileExists(FTPOutputFile7) = True Then
objFSO.DeleteFile(FTPOutputFile7)
End If

'Rotate logs
If objFSO.FileExists(FTPOutputFile6) = True Then
objFSO.MoveFile(FTPOutputFile6, FTPOutputFile7)
End If

If objFSO.FileExists(FTPOutputFile5) = True Then
objFSO.MoveFile(FTPOutputFile5, FTPOutputFile6)
End If

If objFSO.FileExists(FTPOutputFile4) = True Then
objFSO.MoveFile(FTPOutputFile4, FTPOutputFile5)
End If

If objFSO.FileExists(FTPOutputFile3) = True Then
objFSO.MoveFile(FTPOutputFile3, FTPOutputFile4)
End If

If objFSO.FileExists(FTPOutputFile2) = True Then
objFSO.MoveFile(FTPOutputFile2, FTPOutputFile3)
End If

If objFSO.FileExists(FTPOutputFile1) = True Then
objFSO.MoveFile(FTPOutputFile1, FTPOutputFile2)
End If

If objFSO.FileExists(FTPOutputFile) = True Then
objFSO.MoveFile(FTPOutputFile, FTPOutputFile1)
End If

End Sub

Thanks.

Nov 16 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I would use the date in the file name.
Like OutputFiles_yymmdd.log

If there's no way to search a directory
for all the files written prior to a
specific date, you can always iterate
through the files and parse the name
for the date, and delete them.

Robin S.
-----------------------------
<ba*****@yahoo.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
It seems there has got to be a better way to work with log files where
I want to keep 8 days of logs. For instance if I wanted to keep 80
days, this would be a horrible approach. How can I make this more
dynamic and efficient?
Const FTPOutputFile = "output-files.log"
Const FTPOutputFile1 = "output-files-1.log"
Const FTPOutputFile2 = "output-files-2.log"
Const FTPOutputFile3 = "output-files-3.log"
Const FTPOutputFile4 = "output-files-4.log"
Const FTPOutputFile5 = "output-files-5.log"
Const FTPOutputFile6 = "output-files-6.log"
Const FTPOutputFile7 = "output-files-7.log"

Sub Main()
'Do Stuff - gather log information
If a new day
RotateLogFiles()
End if
'Write to log....
End Sub

Sub RotateLogFiles()

'Delete Oldest Log

If objFSO.FileExists(FTPOutputFile7) = True Then
objFSO.DeleteFile(FTPOutputFile7)
End If

'Rotate logs
If objFSO.FileExists(FTPOutputFile6) = True Then
objFSO.MoveFile(FTPOutputFile6, FTPOutputFile7)
End If

If objFSO.FileExists(FTPOutputFile5) = True Then
objFSO.MoveFile(FTPOutputFile5, FTPOutputFile6)
End If

If objFSO.FileExists(FTPOutputFile4) = True Then
objFSO.MoveFile(FTPOutputFile4, FTPOutputFile5)
End If

If objFSO.FileExists(FTPOutputFile3) = True Then
objFSO.MoveFile(FTPOutputFile3, FTPOutputFile4)
End If

If objFSO.FileExists(FTPOutputFile2) = True Then
objFSO.MoveFile(FTPOutputFile2, FTPOutputFile3)
End If

If objFSO.FileExists(FTPOutputFile1) = True Then
objFSO.MoveFile(FTPOutputFile1, FTPOutputFile2)
End If

If objFSO.FileExists(FTPOutputFile) = True Then
objFSO.MoveFile(FTPOutputFile, FTPOutputFile1)
End If

End Sub

Thanks.

Nov 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.