5

I want to use GPSbabel to merge all single .gpx files within one folder into one file called for example merge.gpx how can i archive something like this?

I know how to do it manually:

gpsbabel -i gpx -f "folder/of/file/1.gpx" -f "folder/of/file/2.gpx" -f "folder/of/file/3.gpx" -o gpx -F "folder/of/file/merge.gpx"

But because there are up to 20 such files within one folder i would like to use a batch (.bat) file to do this automatically? I'm nearly completely new to batch files and could not find any information how to archive that.

2 Answers 2

11

For Linux, you could use the following bash script:

#!/bin/bash

cd /folder/of/file
ff=""
for f in *.gpx
do 
    ff="$ff -f $f"
done
gpsbabel -i gpx $ff -o gpx -F "All.gpx"
2

Try this:

setlocal enabledelayedexpansion
cd "folder/of/file"
set f=
for %%f in (*.gpx) do set f=!f! -f "%%f"
gpsbabel -i gpx !f! -o gpx -F "merge.gpx"
4
  • Nice. I was just going to try another option (GPSBabel can read directions from batch (or command) files via the -b option) but this is more elegant. Commented Jul 24, 2016 at 16:49
  • Thats exactly what i needed. Thank you!
    – Kitumijasi
    Commented Jul 26, 2016 at 12:15
  • I also considered the -b option of GPSBabel but with all files being .gpx files I found that quite a hassle to fist build a list of the files and then run the command. Anyway GPSBabel is just a great tool but well the documentation for it in my opinion is not...
    – Kitumijasi
    Commented Jul 26, 2016 at 12:23
  • How would that be for linux?
    – hoge6b01
    Commented Jan 4, 2017 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.