Jump to content

regarding filename


 Share

Recommended Posts

Hello All.

I'm newbie on autoit...

Autoit is really something for various automation.

Here's the question.

How can I put date with filename.txt ?

(I just checked help file and this "General Help and Support" but no luck..maybe I couldn't find it..)

what I want to do is to make log filename with timestamp in c:\tmp like this,

200710051730.log.txt

200710051730: date and time .

log.txt <--- is fixed filename and extension.

How can I make this come true ?

thank you in advance.

Link to comment
Share on other sites

  • Moderators

Try this:

MsgBox(0, 0, _FileToDateTime(@UserProfileDir & "\somefilename.log"))

Func _FileToDateTime($sFileIn)
    ;We should use _PathSplit here, but I'm being lazy
    Local $sPath, $sFName = $sFileIn
    If StringInStr($sFName, "\") Then
        Local $nCount = StringInStr($sFName, "\", 0, -1)
        $sPath = StringLeft($sFName, $nCount)
        $sFName = StringTrimLeft($sFName, $nCount)
    EndIf
    $sFName = @YEAR & @MON & @MDAY & @HOUR & @MIN & "." & $sFName
    Return $sPath & $sFName
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

#Include <Date.au3>
#Include <Array.au3>

$infile = "C:\somefolder\test.log"
$array = StringSplit ( $infile, "\")
$array[$array[0]] = StringRegExpReplace (_NowCalc (), "[^0-9]", "") & $array[$array[0]]
$outfile = _ArrayToString ($array, "\", 1)

MsgBox(0,"",$outfile)oÝ÷ ÚÚºÚ"µÍÒ[ÛYH Ñ]K]LÉÝÂÒ[ÛYH Ð^K]LÉÝÂÙÐÞ
    ][ÝÉ][ÝË[[YÝ[
    ][ÝÐÎÌLÜÛÛYYÛÌLÝÝÙÉ][ÝÊJB[È[[YÝ[
    ÌÍÚ[[JB  ÌÍØ^HHÝ[ÔÜ]
    ÌÍÚ[[K   ][ÝÉÌLÉ][ÝÊB  ÌÍØ^VÉÌÍØ^VÌWHHÝ[ÔYÑ^XÙH
ÓÝÐØ[È

K   ][ÝÖ×NWI][ÝË   ][ÝÉ][ÝÊH   [È ÌÍØ^VÉÌÍØ^VÌWB]Ð^UÔÝ[È
    ÌÍØ^K    ][ÝÉÌLÉ][ÝËJB[[

Edited by weaponx
Link to comment
Share on other sites

  • Moderators

#Include <Date.au3>
#Include <Array.au3>

$infile = "C:\somefolder\test.log"
$array = StringSplit ( $infile, "\")
$array[$array[0]] = StringRegExpReplace (_NowCalc (), "[^0-9]", "") & $array[$array[0]]
$outfile = _ArrayToString ($array, "\", 1)

MsgBox(0,"",$outfile)oÝ÷ Ûú®¢×}÷Ý:.r·ôGb´ôw¢²W¬±Êy«­¢+ÙÕ¹}¥±Q½ÑQ¥µÈ ÀÌØíÍ¥±%¸¤(%1½°ÀÌØíÍAÑ °ÀÌØíÍ9µôÀÌØíÍ¥±%¸(%1½°ÀÌØí¹
½Õ¹ÐôMÑÉ¥¹%¹MÑÈ ÀÌØíÍ9µ°ÅÕ½ÐìÀäÈìÅÕ½Ðì°À°´Ä¤(%%ÀÌØí¹
½Õ¹ÐQ¡¸($$ÀÌØíÍAÑ ôMÑÉ¥¹1Ð ÀÌØíÍ9µ°ÀÌØí¹
½Õ¹Ð¤($$ÀÌØíÍ9µôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíÍ9µ°ÀÌØí¹
½Õ¹Ð¤(%¹%(%IÑÕɸÀÌØíÍAÑ µÀìeHµÀì5=8µÀì5dµÀì!=UHµÀì5%8µÀìÅÕ½Ðì¸ÅÕ½ÐìµÀìÀÌØíÍ9µ)¹Õ¹

Edit2:

Ooops forgot $sPath in last Edit

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Is this better Smoke?

$infile = "C:\somefolder\new folder\test.log"
MsgBox(0,"",StringLeft($infile, StringInStr ($infile, "\", 0 , -1)) & @YEAR & @MON & @MDAY & @HOUR & @MIN & StringTrimLeft ( $infile,StringInStr ($infile, "\", 0 , -1)))oÝ÷ ÚÚºÚ"µÍÌÍÚ[[HH  ][ÝÐÎÌLÜÛÛYYÛÌLÛ]ÈÛÌLÝÝÙÉ][ÝÂÙÐÞ
    ][ÝÉ][ÝËÝ[ÔYÑ^XÙH
    ÌÍÚ[[K   ][ÝÖ×ÌLÉÌL×JÉÌÍÉ][ÝËQPT    [ÈSÓ  [ÈQVH  [ÈÕT  [ÈRSH  [ÈÝ[Õ[SY
    ÌÍÚ[[KÝ[Ò[Ý
    ÌÍÚ[[K   ][ÝÉÌLÉ][ÝËLJJJ
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...