如何将日期和时间写入文件名?
How to write date and time to a file name?
我的 AutoIt 脚本不工作。它应该按实际日期和时间重命名文件。
#include <Date.au3>
#include <File.au3>
FileMove("C:\file.csv", "C:\file" & _NowDate() & _NowTime() & ".csv")
没有语法错误,但文件没有重命名。我认为 Windows 拒绝像 :
或 /
这样的符号。如何将时间转换成这种格式:hh-mm-ss_dd-mm-yyyy
?
"... how to convert time in this format : hh-mm-ss_dd-mm-yyyy?"
根据Documentation - Macro Reference(因为没有可转换的东西):
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
-格式符合字符串排序(按Windows资源管理器显示时间顺序)。
.
您可以在线清理输出
#include <Date.au3>
FileMove("file.csv", "file" & stringreplace(_NowTime(5) , ":" , "-") & "_" &
stringregexpreplace(_NowCalcDate() , "(\d\d\d\d)/(\d\d)/(\d\d)" , "--") &
".csv")
我的 AutoIt 脚本不工作。它应该按实际日期和时间重命名文件。
#include <Date.au3>
#include <File.au3>
FileMove("C:\file.csv", "C:\file" & _NowDate() & _NowTime() & ".csv")
没有语法错误,但文件没有重命名。我认为 Windows 拒绝像 :
或 /
这样的符号。如何将时间转换成这种格式:hh-mm-ss_dd-mm-yyyy
?
"... how to convert time in this format : hh-mm-ss_dd-mm-yyyy?"
根据Documentation - Macro Reference(因为没有可转换的东西):
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
-格式符合字符串排序(按Windows资源管理器显示时间顺序)。
您可以在线清理输出
#include <Date.au3>
FileMove("file.csv", "file" & stringreplace(_NowTime(5) , ":" , "-") & "_" &
stringregexpreplace(_NowCalcDate() , "(\d\d\d\d)/(\d\d)/(\d\d)" , "--") &
".csv")