Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Garmin FIT file to CSV conversion - multiple Java instances and extraneous files

Rank

Total Posts: 1

Joined 2016-10-01

PM

I have successfully figured out how to convert FIT files (produced by a Garmin Forerunner 620 watch) to CSV by using the ANT SDK. The code is in VBA (loop) and contains a shell command to execute the Java JAR file. There are two major annoyances with this method:

1. For each loop 2 instances of java.exe are created - both slowing down the execution and filling the Windows task bar many times over.
2. Each loop creates both a definition file and a lap or session file. The definition files are not needed and are a waste of space.

VBA code:

Sub RunJarJarBinks()

Dim FITfileFOLDER As Object
Dim FiLe 
As Object
Dim FSO 
As Object
Dim FLpath 
As String
Dim wb 
As Workbook
Dim FiLeCollect 
As Object
Dim repNAME 
As String

Set wb 
ThisWorkbook

FLpath 
wb.Path

Set FSO 
CreateObject("scripting.filesystemobject")
Set FITfileFOLDER FSO.GetFolder(FLpath)
Set FiLeCollect FITfileFOLDER.Files

ChDir ThisWorkbook
.Path
    
For Each FiLe In FiLeCollect
        
If Right(FiLe.Name4) = ".FIT" Then
            repNAME 
Replace(FiLe.Name".FIT""") & "_session"
             
SHELL "java.exe -jar FitCSVTool.jar -b      C:\users\devin\downloads\FIT_files\" FiLe.Name " C:\users\devin\downloads\FIT_files\" repNAME " --data"
        
Application.Wait (Now 24 60 60 1)
    
End If
Next

ChDir ThisWorkbook
.Path
    
For Each FiLe In FiLeCollect
        
If Right(FiLe.Name4) = ".FIT" Then
            repNAME 
Replace(FiLe.Name".FIT""") & "_lap"
            
SHELL "java.exe -jar FitCSVTool.jar -b C:\users\devin\downloads\FIT_files\" FiLe.Name " C:\users\devin\downloads\FIT_files\" repNAME " --defn none --data lap"
            
Application.Wait (Now 24 60 60 1)
        
End If
    
Next
End Sub 


I believe the best answer is to utilize the BAT file contained in the SDK. I can drag and drop all the FIT files onto the BAT file, and they convert quickly and without the extra files. So, my question is - if the BAT file is the correct solution, then how do I initialize it in VBA and pass file names to the BAT file (as an array?)? Otherwise, I guess I need to move my loop into the JAR file?

BAT file code:

@echo off

setlocal EnableDelayedExpansion

set APP_DIR
=%~dp0
set APP_NAME
=FitCSVTool.jar
set APP_PATH
="%APP_DIR%%APP_NAME%"

set a=%*

FOR %%
b IN (!a!) DO (
   
set c=%%b
   set c
=!c:.fit=!
   
call java -jar %APP_PATH% -%%!c!
)
pause