Archive: How can I create directory useing current time?


How can I create directory useing current time?
Like this 2004-04-21-19-13-10 (YY-MM-DD-Hour-Min-Sec)


See the NSIS Archive at http://nsis.sf.net/archive for a script to get the current date and time.


You could use the following, if your using NSIS 2.0.
(Taken directly from the documentation) ;)


5.2.3 ${__DATE__}
Date according to the current locale.

5.2.4 ${__TIME__}
Time according to the current locale.

5.2.5 ${__TIMESTAMP__}
Date & time according to the current locale.


You can't use ${__DATE__}, ${__TIME__} and ${__TIMESTAMP__} as they a defines made during compilation. For retrieving the current time/date you have use the nsis datetime plugin which you can find in the archive like Joost posted earlier.


These defines are replaced on compile-time.


When I insert ${__TIMESTAMP__} it give me a error:Invalid command: ${__TIMESTAMP__}.

And what I mean is how can I get the user sysytem current time,not local system time.

I try GetFileTime $R0 $0 $1 but I donot known convert dword to YY-MM-DD format.


As I already said, you should not use ${__TIMESTAMP__} since it is a compile-time defined symbol.

Search the NSIS Archive, it contains a function that allows you to get the current date/time.


THX, I found this code to do it

Section ""
Call GetCurrentTime
Pop $0
DetailPrint "$0"
SectionEnd

Function GetCurrentTime
Push $R0
Push $R1
Push $R2
System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(.R0,,,,,,,)'
StrCpy $R1 $R0

System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(,.R0,,,,,,)'
StrCpy $R2 $R0 "" 1
StrCmp $R2 "" 0 +2
StrCpy $R0 "0$R0"
StrCpy $R1 "$R1-$R0"

System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(,,,.R0,,,,)'
StrCpy $R2 $R0 "" 1
StrCmp $R2 "" 0 +2
StrCpy $R0 "0$R0"
StrCpy $R1 "$R1-$R0"

System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(,,,,.R0,,,)'
StrCpy $R2 $R0 "" 1
StrCmp $R2 "" 0 +2
StrCpy $R0 "0$R0"
StrCpy $R1 "$R1-$R0"

System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(,,,,,.R0,,)'
StrCpy $R2 $R0 "" 1
StrCmp $R2 "" 0 +2
StrCpy $R0 "0$R0"
StrCpy $R1 "$R1-$R0"

System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
System::Call 'kernel32::GetLocalTime(i) i(R0)'
System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)(,,,,,,.R0,)'
StrCpy $R2 $R0 "" 1
StrCmp $R2 "" 0 +2
StrCpy $R0 "0$R0"
StrCpy $R0 "$R1-$R0"

Pop $R2
Pop $R1
Exch $R0
FunctionEnd


Doh! I forgot that little part....