Jump to content

Creating a file/folder with localtime in the name


Recommended Posts

Goal: Create a file with the current (local) time as a part of the name. Problem is time and date outputs use illegal characters "/" and ":".

Example: Project_03_30_2009_17_52_10.txt

I cobbled some code together by using the "search" tool and the help file.

The question is, there is a better way to do this right?

#include <Date.au3>

Dim $tSystem, $tLocal, $TimeDate, $LocalArrayDate, $LocalArrayTime, $TimeDate, $LocalDateForFile, $Combined_DateTime_ForFile
Dim $LocalDateForFile, $LocalTimeForFile

_SystemTimeToLocalTimeArray()

Func _SystemTimeToLocalTimeArray()
  $tSystem = _Date_Time_GetSystemTime()
  $tLocal  = _Date_Time_SystemTimeToTzSpecificLocalTime(DllStructGetPtr($tSystem))
  $TimeDate = StringSplit(_Date_Time_SystemTimeToDateTimeStr($tLocal), ' ', 1)
  $LocalArrayDate = StringSplit($TimeDate[1], '/', 1)
  $LocalDateForFile = $LocalArrayDate[1] & "_" & $LocalArrayDate[2] & "_" & $LocalArrayDate[3]
  $LocalArrayTime = StringSplit($TimeDate[2], ':', 1)
  $LocalTimeForFile = $LocalArrayTime[1] & "_"& $LocalArrayTime[2] & "_" & $LocalArrayTime[3]
Global  $Combined_DateTime_ForFile = "_" & $LocalDateForFile & "_" & $LocalTimeForFile
EndFunc


MSGBOX(0, "Title", $Combined_DateTime_ForFile)
Link to comment
Share on other sites

All you need are macros..

@YEAR,@MON,@MDAY,@HOUR,@MIN,@SEC

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