You are not logged in.
Hey there,
Is there a way to safe a certainly formatted Date from the fileName into a Tdatetime Variable in pascalscript? I didn‘t really find a proper function in the function register.
(Example of format: TT-MM-YYYY)
Thanks
Offline
You are probably interested in these functions:
function FormatDateTime(const Format: String; DateTime: TDateTime): String;
function ScanDateTime(const Pattern, Subject: String): TDateTime;
function TryScanDateTime(const Pattern, Subject: String; out DateTime: TDateTime): Boolean;
Full list of available functions:
https://www.den4b.com/wiki/ReNamer:Pasc … :Functions
Date time format specification:
https://www.den4b.com/wiki/ReNamer:Date_and_Time_format
Offline
Hi,
thanks for the quick answer.
I edited a code i got in my last topic in this forum:
var
DateRegEx:TWideStringArray;
DateString: WideString;
Date:TDateTime;
begin
DateRegEx:=SubMatchesRegEx(FileName,'(\d+_)(\d+)(_\d+)',false);
if Length(DateRegEx) <=0 then exit;
DateString:= DateRegEx[1];
showmessage(DateString);
Date:=ScanDateTime(ddmmyyyy,DateString);
FileName := 'C:\new' +'\'+FormatDateTime('yyyy', Date) +'\'+
FormatDateTime('mm-yyyy', Date)+ '\' + FormatDateTime('mm-yyyy', Date) + '_new.txt';
end.
Everytime i run the code i get the error:
[Line 11]Error: Unknown identifier 'ddmmyyyy'
I hope you can help me fix this issue.
Luro
Offline
Hi Luro,
"ddmmyyyy" is a literal string,
so mark it as a string in PascalScript, same as shown in the errormsg: 'ddmmyyyy'
Else PS will lookup for a variable name ddmmyyyy.
HTH?
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
Thanks a lot ;D
Offline
Luro, from what I can see in your script, this should be achievable without even using the Pascal Script rule.
Consider the following rules:
1) Insert: Insert " " as Prefix (skip extension)
2) Regular Expressions: Replace expression "\A(.*?(\d+_\d+_\d+).*?)\Z" with "$2#$1" (skip extension)
3) Reformat Date: Convert to "yyyy\mm-yyyy\mm-yyyy" from "dd_mm_yyyy#", skip extension
4) Insert: Insert "C:\NEW\" as Prefix (skip extension)
Example input filename:
abc 17_01_2020 xyz.txt
Output path:
C:\NEW\2020\01-2020\01-2020 abc 17_01_2020 xyz.txt
It is not clear what you want to do with the old filename, so these rules will just keep it as is, but let us know if you need further help.
Offline