473,670 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically iterating through log files

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.FileExis ts(FTPOutputFil e7) = True Then
objFSO.DeleteFi le(FTPOutputFil e7)
End If

'Rotate logs
If objFSO.FileExis ts(FTPOutputFil e6) = True Then
objFSO.MoveFile (FTPOutputFile6 , FTPOutputFile7)
End If

If objFSO.FileExis ts(FTPOutputFil e5) = True Then
objFSO.MoveFile (FTPOutputFile5 , FTPOutputFile6)
End If

If objFSO.FileExis ts(FTPOutputFil e4) = True Then
objFSO.MoveFile (FTPOutputFile4 , FTPOutputFile5)
End If

If objFSO.FileExis ts(FTPOutputFil e3) = True Then
objFSO.MoveFile (FTPOutputFile3 , FTPOutputFile4)
End If

If objFSO.FileExis ts(FTPOutputFil e2) = True Then
objFSO.MoveFile (FTPOutputFile2 , FTPOutputFile3)
End If

If objFSO.FileExis ts(FTPOutputFil e1) = True Then
objFSO.MoveFile (FTPOutputFile1 , FTPOutputFile2)
End If

If objFSO.FileExis ts(FTPOutputFil e) = True Then
objFSO.MoveFile (FTPOutputFile, FTPOutputFile1)
End If

End Sub

Thanks.

Nov 16 '06 #1
1 1570
I would use the date in the file name.
Like OutputFiles_yym mdd.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.goo glegroups.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.FileExis ts(FTPOutputFil e7) = True Then
objFSO.DeleteFi le(FTPOutputFil e7)
End If

'Rotate logs
If objFSO.FileExis ts(FTPOutputFil e6) = True Then
objFSO.MoveFile (FTPOutputFile6 , FTPOutputFile7)
End If

If objFSO.FileExis ts(FTPOutputFil e5) = True Then
objFSO.MoveFile (FTPOutputFile5 , FTPOutputFile6)
End If

If objFSO.FileExis ts(FTPOutputFil e4) = True Then
objFSO.MoveFile (FTPOutputFile4 , FTPOutputFile5)
End If

If objFSO.FileExis ts(FTPOutputFil e3) = True Then
objFSO.MoveFile (FTPOutputFile3 , FTPOutputFile4)
End If

If objFSO.FileExis ts(FTPOutputFil e2) = True Then
objFSO.MoveFile (FTPOutputFile2 , FTPOutputFile3)
End If

If objFSO.FileExis ts(FTPOutputFil e1) = True Then
objFSO.MoveFile (FTPOutputFile1 , FTPOutputFile2)
End If

If objFSO.FileExis ts(FTPOutputFil e) = True Then
objFSO.MoveFile (FTPOutputFile, FTPOutputFile1)
End If

End Sub

Thanks.

Nov 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1928
by: Satish Kumar Chimakurthi | last post by:
Hi all, An external solver program is dynamically producing files with different names 0000001.dat, 0000002.dat, 0000003.dat etc.....at regular intervals. These files contain all numeric data. Is it possible to read each of these dynamically in python ?? If so, how should my code look like ?? If it was not dynamically required, then, I would change the name of the file in my *open* statement every time and read the corresponding one. But...
0
1257
by: ischenko | last post by:
Hi, I'm trying to find all modules that contain doctests and execute them (using DocTestSuite). The problem is how to iterate (programmatically) through the package's modules. >>> import M >>> inspect.getmembers(M, inspect.ismodule)
1
2909
by: John | last post by:
Hi, we have the following problem: in our application v1.0 we have static html pages (+ some javascript). With a CMS (a Content Management System) some "mortal" people can add or expand the available images for the start site. The site loads randomly an image or a Flash animation (if the flash plugin is present) through a javascript and each time the start site loades and displays only 1 different picture. At the moment the name of...
8
2178
by: Arpan | last post by:
A Form has a select list which lists all the column names of a SQL Server database table. Users will select one or more than one column from this select list & after submitting the Form, the records of only those columns that he had selected in the previous page will be displayed to him. This is the Form code: ---------------------------------------- strSQL="SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='tblSheet'...
3
2047
by: Dan Kjaergaard | last post by:
Hi I created a program using C#, which iterates files and displays these in a listview. However I would like to filter the files, so files won't be displayed if the current user hasn't "read access" any clever way to do that in the .NET Framework using C#? thanks
2
1224
by: Dan | last post by:
hi ng, in my asp.net application, users dynamically can create aspx files and codebehinds (and other source files). how can i enforce .net to add these sources to the .dll? til now, the user gets the error Parser Error Message: Could not load type ''. thanks you very much.
2
1586
by: wapsiii | last post by:
I have a form to which I add sets of input controls ie. textbox 1, dropdownlist 1, textbox 2, dropdownlist 1, textbox 3, dropdownlist 3. The number of sets vary. I give them unique IDs the following way: txt_1, ddl_1, txt_2, ddl_2, txt_3, ddl_3. When the form is submitted I retrieve the values of the dynamically added controls by iterating over the request.form collection looking for IDs txt_ and ddl_
3
1393
by: Lie | last post by:
When you've got a nested loop a StopIteration in the Inner Loop would break the loop for the outer loop too: a, b, c = , , def looper(a, b, c): for a_ in a: for b_ in b: for c_ in c: print a_, b_, c_
1
3945
by: ramel | last post by:
Hi all, I have a problem related to javascript , ajax and jsp. Please see this url http://xil.co.in/print_screen_2.JPG. I am working on this form. There are some buttons (like submit , add ,edit at bottom of this page , but not visible in printscreen). On click of a radio button on left side , form fields on right side and small table on right bottom is gettig populated. The table on right bottom , is actually the eligibility...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7419
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2042
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.