Jump to content

Create File With variable filename


Recommended Posts

Hello All

I am writing a script that needs to maintain a logfile.

A new logfile needs to be created each time the script is run, wihtout overwriting the previous logfiles.

What I would like to do is includes the Timedatestamp in the filename.

I knowhow to get the timedatestamp but need help inlcuding this as part of the filename..I.e How do I include the $TimeStamp variabel i the filename below...?

Log_File_28 Ma_2005_13:05.txt

Dim $TimeStamp

FileWrite ("C:\folder\LogFile.txt", "THis is a logfile")

Cheers

Rich

Link to comment
Share on other sites

Hello All

I am writing a script that needs to maintain a logfile.

A new logfile needs to be created each time the script is run, wihtout overwriting the previous logfiles.

What I would like to do is includes the Timedatestamp in the filename.

I knowhow to get the timedatestamp but need help inlcuding this as part of the filename..I.e How do I include the $TimeStamp variabel i the filename below...?

Log_File_28 Ma_2005_13:05.txt

Dim $TimeStamp

FileWrite ("C:\folder\LogFile.txt", "THis is a logfile")

Cheers

Rich

<{POST_SNAPBACK}>

FileWrite ("C:\folder\" & $TimeStamp, "THis is a logfile")
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hello Again,

Just relealised that the previous reply was not what I was intending to ask - although useful nonetheless.

I have a logfile that is written to each time the script is run, each entry is timedatestamped.

However I want to start a new logfile with each new day.

I.e If the script is run on Monday the file Logfile_Mon.txt is created adn each subsequent run of the script on Monday appends to this file.

But when the script is run on say Tuesday, the file LogFile_Tues.txt is created, and so on...

Link to comment
Share on other sites

#include <file.au3>

_FileWriteLog(("C:\folder\LogFile.txt", "THis is a logfile")

<{POST_SNAPBACK}>

Hi Again

Either I've misunderstood your reply or im not explaining myself well...

If I use the command above the filename will always be the same I.e. LogFile.log

I want the filename to change, here is what I have so far:

;*** CREATE LOG FILE

;**

;*

FileChangeDir("C:\usr\TTS Config\PCSound")

$File = FileOpen ("Sound LogFile.txt" , 1 )

If $File = -1 Then

MsgBox(0, "Error", "Unable to Create PCSound Logfile.")

Exit

EndIf

And to write timstamped entries to it:

$TimeStamp = _DateTimeFormat( _NowCalc(),0)

FileWriteLine ( $File, $TimeStamp & " Starting PC Sound" )

I want the Sound LogFile.txt to intead change;

LogFile_Mon.txt OR LogFile_28Jul2005.txt

I have tried...

$File = FileOpen ("Sound LogFile_.txt" & $Timestamp, 1 )

Thanks again

Link to comment
Share on other sites

Select
   Case @WDAY = 1
      $file = "LogFile_Sun.txt"
   Case @WDAY = 2
      $file = "LogFile_Mon.txt"
   Case @WDAY = 3
      $file = "LogFile_Tue.txt"
   Case @WDAY = 4
      $file = "LogFile_Wed.txt"
   Case @WDAY = 5
      $file = "LogFile_Thu.txt"
   Case @WDAY = 6
      $file = "LogFile_Fri.txt"
   Case @WDAY = 7
      $file = "LogFile_Sat.txt"
EndSelect

#include <file.au3>

_FileWriteLog($file,  "THis is a logfile")

_FileWriteLog puts a time stamp at the beginning of the line it writes to the file.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Here's another option for setting the file name:

MsgBox(0, "log name", _SetLogFileName())
MsgBox(0, "log name", _SetLogFileName(1))

Func _SetLogFileName($flag = 0)
   Local $file = "LogFile_"
   If $flag Then
      $file = $file & @MDAY
      Select
         Case @MON = '01'
            $file = $file & "Jan"
         Case @MON = '02'
            $file = $file & "Feb"
         Case @MON = '03'
            $file = $file & "Mar"
         Case @MON = '04'
            $file = $file & "Apr"
         Case @MON = '05'
            $file = $file & "May"
         Case @MON = '06'
            $file = $file & "Jun"
         Case @MON = '07'
            $file = $file & "Jul"
         Case @MON = '08'
            $file = $file & "Aug"
         Case @MON = '09'
            $file = $file & "Sept"
         Case @MON = '10'
            $file = $file & "Oct"
         Case @MON = '11'
            $file = $file & "Nov"
         Case @MON = '12'
            $file = $file & "Dec"
      EndSelect
      $file = $file & @YEAR & ".txt"
   Else
      Select
         Case @WDAY = 1
            $file = $file & "Sun.txt"
         Case @WDAY = 2
            $file = $file & "Mon.txt"
         Case @WDAY = 3
            $file = $file & "Tue.txt"
         Case @WDAY = 4
            $file = $file & "Wed.txt"
         Case @WDAY = 5
            $file = $file & "Thu.txt"
         Case @WDAY = 6
            $file = $file & "Fri.txt"
         Case @WDAY = 7
            $file = $file & "Sat.txt"
      EndSelect
   EndIf
   Return $file
EndFunc  ;==>_SetLogFileName

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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