You are not logged in.
I got lots of files named as:
1590333218.jpg
1590333221.jpg
...
would like to rename them to readable date time format, yyyymmdd_hhmmss.jpg
I had inspect the rules, finally I goes to 'Pascal Script'.
(If there is more simple way to achieve this with other Rules, please let me know. thanks.)
here is my current progress:
begin
FileName := DateToStr(
UnixToDateTime(
StrToInt64(FileName)
)
);
end
Tried to compile, it give me error 'period ('.') expected', and during my 2 hours work, there was also lots of 'type' errors as well.
I am not familiar with programming, this is first time to do with Pascal, I am quite confusing, so would like to ask help from here,
anybody can sort this script out for me?
thanks.
Last edited by mxmjykoj2 (2020-05-24 16:23)
Offline
Hi and welcome.
Very well done so far, congratulations.
'period ('.') expected' probably refers to the missed dot which is mandatory for the last "end".
- - -
You have to know that the variable "FileName" contains, well, the file name, which is like "1590333218.jpg"
And "1590333218.jpg" is no TDateTime but an string with dot and extension.
So try to work with the base name "1590333218" only.
See http://www.den4b.com/wiki/ReNamer:Pasca … :Functions
WideExtractBaseName(FileName)
WideExtractFileExt(FileName)
FROM:
1590333218.jpg
TO:
24.05.2020.jpg
USE:
begin
FileName := DateToStr(
UnixToDateTime(
StrToInt64(
WideExtractBaseName(FileName)
)
)
)
+ WideExtractFileExt(FileName);
end.
But "DateToStr()" is not the right one for your wanted result 'yyyymmdd_hhmmss', because the description reads
like "Converts a date to a string, using system format for the short date, for example: dd/mm/yyyy"
Unfortunately, I don't know which function else to use, I have to try that first with the functions from
http://www.den4b.com/wiki/ReNamer:Pasca … :Functions
EDIT: got it
//function FormatDateTime(const Format: String; DateTime: TDateTime): String
//myString := FormatDateTime('yyyymmdd_hhmmss', <here an TDateTime>) ;
FROM:
1590333218.jpg
TO:
20200524_151338.jpg
begin
FileName :=
FormatDateTime( 'yyyymmdd_hhmmss' ,
UnixToDateTime(
StrToInt64(
WideExtractBaseName(FileName)
)
)
)
+ WideExtractFileExt(FileName);
end.
- - -
Code cleaned up for others with explanation:
FROM:
1590333218.jpg
TO:
20200524_151338.jpg
Use PascalScript
http://www.den4b.com/wiki/ReNamer:Rules:PascalScript
PascalScript code:
var
myBasename,myDateTime:WideString;
myUnixTimeStamp:TDateTime;
begin
//filename is like "1590333218.jpg" , basename is an Unix Time Stamp like "1590333218"
//"1590333218" should result to "05/24/2020 @ 3:13pm (UTC)" (see www.unixtimestamp.com/)
//
myBasename := WideExtractBaseName(FileName);
//function UnixToDateTime(U: Int64): TDateTime; Converts a Unix timestamp to a value of TDateTime type.
myUnixTimeStamp := UnixToDateTime( StrToInt64(myBasename) );
//function FormatDateTime(const Format: String; DateTime: TDateTime): String
//which results for "1590333218" , format to 'yyyymmdd_hhmmss' , as "20200524_151338"
myDateTime := FormatDateTime('yyyymmdd_hhmmss', myUnixTimeStamp);
FileName := myDateTime + WideExtractFileExt(FileName);
end.
//--or something like this, if somebody want:
FileName := myBasename + '_(' + myDateTime + ')' + WideExtractFileExt(FileName);
// >> 1590333218_(20200524_151338).jpg
FileName := myDateTime + '_(' + myBasename + ')' + WideExtractFileExt(FileName);
// >> 20200524_151338_(1590333218).jpg
Last edited by Stefan (2020-05-24 17:23)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Wow! Thank you very much, that's the best answer I've ever gotten in cyber! I love your software and your personality!
I do expect more software you can provide, but I will definitely buy when I need it.
You're a star!
Offline