Jump to content
Sign in to follow this  
SeattleSteve

FileOpen following FileMove inherits original Create Date

Recommended Posts

SeattleSteve

I have a simple script that tries to rename a file when it's Create Date is different than today's date. This is so we can save a daily log file off to the side and then create a new empty one. The 'active' log file is called "GAK_Capture.log" and the renamed one has the date imbedded in the name (i.e. "GAK_Capture_20091012.log"). We are running AutoItV3.

We try to use the FileMove function call to rename/move the file and then we issue a FileOpen to create the new active file. What we've noticed is that when all of this occurs within the scope of one script then the 'new' file actually inherits the Create Date of the original file. Is this a bug in AutoItV3? Can anyone tell me of any other way to do this outside of running two separate scripts? Here's our simple script:

*****************************************

$GalaxyPath = "C:\Program Files\Gateway Ticketing Systems\Galaxy\"

$GakLog = $GalaxyPath & "GAK_Capture.log"

$Today = @YEAR & @MON & @MDAY

if FileExists ($Gaklog) Then

$FTime = FileGetTime ($Gaklog, 1)

If ($Today <> $FTime[0] & $FTime[1] & $FTime[2]) Then

FileMove ($GakLog, $GalaxyPath & "Logs\Gak_Capture_" & $Today & ".log")

EndIf

EndIf

if Not FileExists($GakLog) Then

$file = FileOpen ($GakLog, 1)

FileClose ($file)

EndIf

*****************************************

We've confirmed that after a successful FileMove the second "If Not FileExists" processes properly and we see a new, empty file being created. Unfortunately it still has the Create Date of the original file...over and over and over.

Any and all feedback/advice is greatly appreciated.

Steve

Edited by SeattleSteve

Share this post


Link to post
Share on other sites
botanic

try this

$GalaxyPath = "C:\Program Files\Gateway Ticketing Systems\Galaxy\"
$GakLog = $GalaxyPath & "GAK_Capture.log"
$Today = @YEAR & @MON & @MDAY

if FileExists ($Gaklog) Then
$FTime = FileGetTime ($Gaklog, 1)
If ($Today <> $FTime[0] & $FTime[1] & $FTime[2]) Then
FileMove ($GakLog, $GalaxyPath & "Logs\Gak_Capture_" & $Today & ".log")
$file = FileOpen($GalaxyPath & "GAK_Capture.log", 1)
FileClose ($file)
EndIf
EndIf

also if FileMove returns a 0 that means that the file cant be moved so its just copying it instaed

Edited by botanic

Share this post


Link to post
Share on other sites
SeattleSteve

I tried your suggestion, to no avail. I even changed the reference to $GakLog in the FileMove to be the concatenation of the $GalaxyPath and the quoted string, like your recommended change in the FileOpen command.

It also turns out that FileMove is returning a value of 1 so that it is truly moving the file. I can put a sleep in between the steps and watch the file disappear; when the 'new' file shows up it still has the Create Date of the original file.

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  

×