Sign in to follow this  
Followers 0
inspu

Appending date and time with file name

8 posts in this topic

Hi

I am creating a log file.And i need date and time should be append with the file name.I tried as follows but not working.

; Show current local time

$tCur = _Date_Time_GetLocalTime()

$tCur1 = _Date_Time_SystemTimeToDateTimeStr($tCur)

MsgBox(0, "Timevalue", _Date_Time_SystemTimeToDateTimeStr($tCur))

$file = FileOpen($tCur1+".txt", 1)

I am getting the value in MsgBox.But file name is not creating.Can anyone help me.

Share this post


Link to post
Share on other sites



Hi

I am creating a log file.And i need date and time should be append with the file name.I tried as follows but not working.

; Show current local time

$tCur = _Date_Time_GetLocalTime()

$tCur1 = _Date_Time_SystemTimeToDateTimeStr($tCur)

MsgBox(0, "Timevalue", _Date_Time_SystemTimeToDateTimeStr($tCur))

$file = FileOpen($tCur1+".txt", 1)

I am getting the value in MsgBox.But file name is not creating.Can anyone help me.

Try with option 9. See help for detail.

$file = FileOpen($tCur1+".txt", 9)


Share this post


Link to post
Share on other sites

Sorry this didnt work for me...

Moreover i didnt see option 9 in help file

Share this post


Link to post
Share on other sites

Without more of your code, I can't be sure this will work, but I think it will:

$tCur = _Date_Time_GetLocalTime()
$tCur1 = _Date_Time_SystemTimeToDateTimeStr($tCur)
MsgBox(0, "Timevalue", _Date_Time_SystemTimeToDateTimeStr($tCur))
FileCopy("", @scriptdir & "\" & $tCur1+".txt", 8) ; <-- the 8 creates a blank file
$file = FileOpen(@scriptdir & "\" & $tCur1+".txt", 1)
FileWrite($file, _Date_Time_SystemTimeToDateTimeStr($tCur))

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

I think i cinfused all.

I need a file name with date and time.

Eg:"testReport05/30/2011.txt"

I dont want to write date and time into the file.File name should have date and time.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I think i cinfused all.

I need a file name with date and time.

Eg:"testReport05/30/2011.txt"

I dont want to write date and time into the file.File name should have date and time.

inspu - "/" and ":" will be illegal characters for a file name.

Also 9 was a combo of 1 = Append and 8 = Create the file structure.

You can try:

#Include <Date.au3>
$tCur = _Date_Time_GetLocalTime()
 $tCur1 = _Date_Time_SystemTimeToDateTimeStr($tCur)
$tCur1 = StringReplace( $tCur1, "/","_")
$tCur1 = StringReplace( $tCur1, ":","_")
MsgBox(0, "Timevalue", $tCur1 )
 $file = FileOpen($tCur1&".txt", 9)
 If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
FileWrite($file , $tCur1)
FileClose($file)
ShellExecute($tCur1&".txt")

You can also investigate _FileWriteLog

Edited by JoHanatCent

Share this post


Link to post
Share on other sites

Thanks This is working

Share this post


Link to post
Share on other sites

Thanks This is working

You're welCome.

Share this post


Link to post
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
Sign in to follow this  
Followers 0