Jump to content

Weekly Log


Recommended Posts

im looking for a good _func that will generate a new text file every week with the full week being sunday - saturday. but im going to be writing to it all week to, so i need to it be able to figure out if i run my script on tuesday, that it is a new week and to generate a new log, and keep writing to it all week, then the following monday, or tuesday or what ever, makes a new log to start writing to. calling it like 2010/x/y_2010/a/b.txt. this would be awesome, thanks for your help in advanced.

Link to comment
Share on other sites

You'll want to look at the Date UDF.

Oh, and generally I use the yyyymmdd.yyyymmdd.log.txt format for these kind of things so when you look at them in Explorer they are automatically sorted by date, and you can split them into [start, finish, filename] easily.

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

can you give me an example script, i am still pretty new to programing in general. im just starting to write functions.

Show us what you got so far. Which part of writing the function are you getting stuck on?

Link to comment
Share on other sites

mostly on a way to identify the current date to a a date range, i was thinking that that would be the best way to do this, it would to return a date then find out it if it falls between @NowWeek (i know not real), if true, then write to the current log file, if not true generate a new log file. i keep trying to work it out it my head to come up with an idea on how to do this, but am getting now where.

Edited by redLabel
Link to comment
Share on other sites

okay, im making an attempt at this, and im sure it is going to be terrible, so any help anybody has for me will be very appreciated. thanks in advanced

Func _WorkLogName()
    $dayNow = @WDAY
    If $dayNow = 1 Then $dayNow -= 0
    If $dayNow = 2 Then $dayNow -= 1
    If $dayNow = 3 Then $dayNow -= 2
    If $dayNow = 4 Then $dayNow -= 3
    If $dayNow = 5 Then $dayNow -= 4
    If $dayNow = 6 Then $dayNow -= 5
    If $dayNow = 7 Then $dayNow -= 6
    $date = _DateTimeFormat(@YEAR & "/" & @MON & "/" & _DateDayOfWeek($dayNow, 0), 0)
    If FileExists(@ScriptDir & $date & "*" & ".txt") Then
        ;==> code here for all the information i want to write to the text ;
    Else
        FileWrite(@ScriptDir & $date & "." & _DateAdd('D', 7, $date) & ".txt", "") ;==> code to write to new ;
    EndIf
EndFunc

i know, bad.

Edited by redLabel
Link to comment
Share on other sites

Not that bad, actually. There were some easier ways to do it, have fun playing around with this:

#include <Date.au3>

Func _OpenLogFile()
    local $currentDate = _NowCalcDate()
    local $weekStart = _DateAdd ('D', -(@WDAY - 1), $currentDate)
    local $weekEnd = _DateAdd ('D', 7 - @WDAY, $currentDate)

    Local $fileName = StringReplace ($weekStart & '.' & $weekEnd & ".txt", "/", '')
    
    If Not FileExists(@ScriptDir & "\" & $fileName) Then
        FileWrite(@ScriptDir  & "\" & $fileName, "") ;==> code to create new file
    EndIf
    
    Return FileOpen (@ScriptDir  & "\" & $fileName, 1) ;Returns a file handle you can use to write your logs to
EndFunc

The major changes were the name, and that the function now returns a handle to an open file which you can use to write to your log multiple times. The only 'gotcha' is that you have to close it before you end your script.

If you don't need to write often, replace the end bit with what you have above and it should work np, I mainly did it this way because I like the idea, and will probably end up using this function myself.

Cheers

Fulano

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...