Batch Rename Tracks in GPX from Filename

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Batch Rename Tracks in GPX from Filename

ForestCat
Hi,
   I have a LOT of GPX track files exported from  Google My Tracks.  They typically only have one actual track per GPX file.  Is there a way to batch rename these tracks (inside the gpx) to match the gpx filename?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Batch Rename Tracks in GPX from Filename

Robert Lipe-4
Hi, and welcome.

We don't really have a way to do that.  Our writers don't know the filenames of where the data comes from - it may, in fact, not have even come from a file or it could have been altered by an upstream filter, for example - so it's not even something we could trivially add.  

Honestly, this kind of thing is probably better done in the space of a general purpose programming language or text editing tool like python, sed, awk, perl, whatever.  It's probably a program under a dozen lines in about any language if you have really careful control and intimate knowledge of the source GPX.  Just riffing from the top of my head on a UNIX-like substance, my starting place would look something like:

for f in *.gpx
do
  bn=$(basename $f)
  sed -ie "s#<name>.*</name>#<name>$bn</name>#" $f 
done

This relies on the name tag already being in the GPX, the files being named something.gpx, and haveing opening/data/close all on one line and other houses of cards that may or may not be true in your case.

It's probably not terribly hard, but GPSBabel is probably the wrong starting place.

Good luck.


On Mon, Oct 19, 2015 at 10:13 AM, ForestCat <[hidden email]> wrote:
Hi,
   I have a LOT of GPX track files exported from  Google My Tracks.  They
typically only have one actual track per GPX file.  Is there a way to batch
rename these tracks (inside the gpx) to match the gpx filename?

Thanks



--
View this message in context: http://gpsbabel.2324879.n4.nabble.com/Batch-Rename-Tracks-in-GPX-from-Filename-tp11749.html
Sent from the GPSBabel - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
Gpsbabel-misc mailing list http://www.gpsbabel.org
[hidden email]
To unsubscribe, change list options, or see archives, visit:
https://lists.sourceforge.net/lists/listinfo/gpsbabel-misc


------------------------------------------------------------------------------

_______________________________________________
Gpsbabel-misc mailing list http://www.gpsbabel.org
[hidden email]
To unsubscribe, change list options, or see archives, visit:
https://lists.sourceforge.net/lists/listinfo/gpsbabel-misc
Reply | Threaded
Open this post in threaded view
|

Re: Batch Rename Tracks in GPX from Filename

ForestCat
Robert,

Thanks for the feedback.  Maybe I've explained it wrong, :-) . I haven't used GPSBabel, so bear with my ignorance.  If I understand correctly, it is a command line utility, which given a filename in some supported format (i.e. .gpx),  is able to modify/convert that file and write it back out to the the same or a different file/format?  If that's correct, then gpsbabel would know the filename since it was given as a commandline param?  All I want to do is rename the internal "name tag" to match the physical file name.  The tricky part is doing this as a batch for a folder of gpx files, since gpsbabel (or some type of scripting language, etc) would need to be able to iterate through a folder of gpx files.  Does that make any more sense?

Does the "name tag" always exist as a delimited field, or at some standard offset into the gpx file?

Is there a parameter/command option for gpsbabel to replace/write the "name tag"?

I'm in the windows environment, but I could throw together a nix box if that's easier
Reply | Threaded
Open this post in threaded view
|

Re: Batch Rename Tracks in GPX from Filename

Robert Lipe-4


On Mon, Oct 19, 2015 at 3:10 PM, ForestCat <[hidden email]> wrote:
Robert,

Thanks for the feedback.  Maybe I've explained it wrong, :-) . I haven't
used GPSBabel, so bear with my ignorance.  If I understand correctly, it is
a command line utility, which given a filename in some supported format
(i.e. .gpx),  is able to modify/convert that file and write it back out to
the the same or a different file/format?  If that's correct, then gpsbabel
would know the filename since it was given as a commandline param? 

I explained that our readers and writers aren't directly connected and that it's not trivial to change the app to work the way you want.

If you want a custom version that does this and that can assume exactly one input and one output, send me specs and I'll give you a quote for a custom version of GPSBabel that'll preserve the input filename as a parent attribute of the data and modify the writers to optionally create it.

I don't know your time/money tradeoff, but if this is a one-time need even for a few million files, I'd probably still recommend the scripted/text editing approach over building a hacked up GPSBabel.


name.  The tricky part is doing this as a batch for a folder of gpx files,
since gpsbabel (or some type of scripting language, etc) would need to be
able to iterate through a folder of gpx files.  Does that make any more
sense?

Which is why I showed you how to do it in one scripting language. There are many you can do it in.

Does the "name tag" always exist as a delimited field, or at some standard
offset into the gpx file?

GPX is plain ole XML; you can edit it as text.  (As long as it's still XML when you're done with it.)


 
Is there a parameter/command option for gpsbabel to replace/write the "name
tag"?

No.

 
I'm in the windows environment, but I could throw together a nix box if
that's easier

Everything is easier to automate when not using Windows, but that's a personal distaste. :-) 

------------------------------------------------------------------------------

_______________________________________________
Gpsbabel-misc mailing list http://www.gpsbabel.org
[hidden email]
To unsubscribe, change list options, or see archives, visit:
https://lists.sourceforge.net/lists/listinfo/gpsbabel-misc
Reply | Threaded
Open this post in threaded view
|

Re: Batch Rename Tracks in GPX from Filename

ForestCat
Thank you, Robert.  I got an xml editor, snopped around, & found the tags I was looking for.  I appreciate the tip.