#1 2020-01-16 18:28

Luro
Member
From: Germany
Registered: 2019-09-19
Posts: 10

Save Date from FileName in TDateTime var in PascalScript

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

#2 2020-01-17 02:01

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Save Date from FileName in TDateTime var in PascalScript

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

#3 2020-01-17 10:37

Luro
Member
From: Germany
Registered: 2019-09-19
Posts: 10

Re: Save Date from FileName in TDateTime var in PascalScript

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

#4 2020-01-17 10:47

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Save Date from FileName in TDateTime var in PascalScript

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

#5 2020-01-17 10:50

Luro
Member
From: Germany
Registered: 2019-09-19
Posts: 10

Re: Save Date from FileName in TDateTime var in PascalScript

Thanks a lot ;D

Offline

#6 2020-01-17 14:38

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Save Date from FileName in TDateTime var in PascalScript

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

Board footer

Powered by FluxBB