-1

My AutoIt script doesn't work. It should rename files by actual date and time.

#include <Date.au3> 
#include <File.au3>
FileMove("C:\file.csv", "C:\file" & _NowDate() & _NowTime() & ".csv")

There is no syntax error, but the file isn't renamed. I think Windows rejects symbols like : or /. How to convert time to this format: hh-mm-ss_dd-mm-yyyy?

user4157124
  • 2,809
  • 13
  • 27
  • 42

2 Answers2

1

"... how to convert time in this format : hh-mm-ss_dd-mm-yyyy?"

As per Documentation - Macro Reference (as there is nothing to convert):

Global Const $g_sPathFile = 'C:\file.csv'
Global Const $g_sFormat   = '%s-%s-%s_%s-%s-%s'
Global Const $g_sTime     = StringFormat($g_sFormat, @HOUR, @MIN, @SEC, @MDAY, @MON, @YEAR)
Global Const $g_sNameNew  = StringReplace($g_sPathFile, '.', $g_sTime & '.', -1)

FileMove($g_sPathFile, $g_sNameNew)

yyyymmddhhmmss -format conforms to string sort (displays chronological order by Windows Explorer).

Related.

user4157124
  • 2,809
  • 13
  • 27
  • 42
0

you can sanitize the output inline

#include <Date.au3>
FileMove("file.csv", "file" & stringreplace(_NowTime(5) , ":" , "-") & "_" & 
stringregexpreplace(_NowCalcDate() , "(\d\d\d\d)/(\d\d)/(\d\d)" , "$3-$2-$1") & 
".csv")
iamtheky
  • 134
  • 1
  • 1
  • 3