|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamically iterating through log filesI 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. 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. ----------------------------- <bay_***@yahoo.com> wrote in message Show quoteHide quote news:1163704807.633312.304110@k70g2000cwa.googlegroups.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. >
appsetting in class doesn't work
RaiseEvent Howto Identify an Exception? Speeding up array/file loading Export function from VB.Net DLL vb 2005 standard question Can a base class implement a method on an interface for me? passing parameter to class from application my class library doesn't contain an assembly - how to add an assem how mutch memory aspnet_wp.exe must use |
|||||||||||||||||||||||