#1 2025-02-11 23:14

Toto Lembrouille
Member
Registered: 2025-02-11
Posts: 4

Extract the second <time> tag from a GPX file

Hello,

I'm very interested by this topic: Extract date from a GPX file

Is there a way to take the second <time> tag, not the first one?
In my files the first <time> tag is the date of the file, not the date of the day that the activity occurs.
I put a sample file in attached.
987541786-gpx.txt

Can you help me please?
Regards

Offline

#2 2025-02-12 02:56

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

Re: Extract the second <time> tag from a GPX file

You can use a Pascal Script rule to extract the second <time> tag from a GPX file.

The content will be inserted as is into the filename, e.g. "2014-08-24T05:21:45Z", so you'll have to clean it up a bit to you liking, with other rules perhaps.

var
  Content: WideString;
  Matches: TWideStringArray;
begin
  if (Length(FilePath) > 0) and WideFileExists(FilePath) then
  begin
    Content := FileReadText(FilePath);
    Matches := SubMatchesRegEx(Content, '<time>.*?</time>.*?<time>(.*?)</time>', False);
    if Length(Matches) > 0 then
      FileName := Matches[0] + ' ' + FileName;
  end
end.

Offline

#3 2025-02-12 07:02

Toto Lembrouille
Member
Registered: 2025-02-11
Posts: 4

Re: Extract the second <time> tag from a GPX file

Hello,
Thank you for your quick answer smile!
Therefore, there an error and it's impossible to rename the file.
7BN0.jpg

Do you have any idea?

Regards.

Regards.

Offline

#4 2025-02-12 07:09

Toto Lembrouille
Member
Registered: 2025-02-11
Posts: 4

Re: Extract the second <time> tag from a GPX file

It seems to be the character ":" that is guilty. This character is not allowed for file names.
How can I sol the pb?

Last edited by Toto Lembrouille (2025-02-12 07:10)

Offline

#5 2025-02-12 09:10

Toto Lembrouille
Member
Registered: 2025-02-11
Posts: 4

Re: Extract the second <time> tag from a GPX file

I finally solve my problem by adding another rule to replace ":" by "-".

Offline

Board footer

Powered by FluxBB