Jump to content

Generate File Name


Brent
 Share

Recommended Posts

What I'm wanting to do is each month save some log files with a set name and the month and year appeneded to the file name. eg log january 2007, log february, 2007 etc. (log 01/07 or similar would be fine)

I have my script working to the point where it runs the program, navigates to the second last set of data, exports it and brings up a save dialog box (standard windows save dialog), and about this point I'm stuck. I can manually send it some text, and hit the save button, that's not a problem. What I need is a way for it to automatically pick up the current month, or preferable the previous month, and the year, and add this to the text I manually send.

Thanks in advance for any advice.

Link to comment
Share on other sites

I have actually coded something almost exactly like that... i'll post my code here...

#include <Date.au3>
Func writetofile()
    $sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
    Dim $Y, $M, $D
    $sJulDate = _DayValueToDate ($sJulDate, $Y, $M, $D)
    $filename = "P:\"
    $filename = $filename &  $Y & "" & $M & "" & $D & "log.txt";this will make a txt file with todays date as the name, ie "20070116log.txt"
    $file = FileOpen($filename, 1) 

    If $file = -1 Then
        if ($debug) then      MsgBox(0, "Error", "Unable to open log file: " & $filename)
        Exit
    EndIf
    FileWrite($file, "this is stuff written inside the file")
    FileClose($file)
EndFunc

This will actually create the file automatically, it wont bring up a save box or anything... if you want to just send the date to the savebox field, then just do something like

send($y) or whatever date you want to send. My code is not perfect, but it works. hopefully that gives you some ideas.

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...