Garmin Log Renaming.rb
# Copy and rename files from Year Downloads to Year Massaged folder and create list of those new files
Copy and rename files from Year Downloads to Year Massaged folder and create list of those new files
Copy and rename files from Year Downloads to Year Massaged folder and create list of those new files
def copyMotionX(newFiles,baseFolderGPX, folderDownload)
  puts "\n6. (165). Copying MotionX gpx files\n from #{folderDownload} to Massaged Folder and \nadding to newFiles, the list of files to be processed."
  i = 0
  folderNew = "167. folderDownload: #{folderDownload}"
  today = Time.now.strftime("%Y%m%d")
  puts 
  Find.find(folderDownload) do |fx|
   next if !File.file?(fx) 
  Find.prune if File.extname(fx) != '.gpx' 
  puts "\n174. fx: #{fx}. \nFile.basename(fx): \n #{File.basename(fx)}"
  dotDate = motionXdate(fx)
  puts "#{lineNum}. dotDate: #{dotDate}"
  yearFile = dotDate[0..3]
  dateFile = dotDate.gsub(".","")
  puts "dateFile: #{dateFile}"
  puts folderNew = "#{baseFolderGPX}#{yearFile} Massaged" 
  newBasename = "#{dotDate} - #{File.basename(fx)}" 
  puts "\n\n184. newBasename: #{newBasename}"
   if today==File.basename(fx, ".TEMP.gpx")
  puts "\n194. today: #{today}. dateFile: #{dateFile}"
  if today==dateFile
      puts "193.. fx: #{fx}"
      fileshortnew = newBasename + ".TEMP" 
      fnew = "#{folderNew}/#{fileshortnew}.gpx"
      puts "201.. fnew: #{fnew}."
   else all but today's file
      fnew = "#{folderNew}/#{newBasename}.gpx"
      puts "204. fnew: #{fnew}."
    end today==. Add TEMP to today's files
    puts "207.. fx: #{fx}. "
    if !File.exists?(fnew)
      puts "209.. fnew: #{fnew}. "
      newFiles << fnew
      FileUtils.cp(fx, fnew) 
      i =+ 1
    end  !File.exists?(fnew). add to newFiles 
  end Find.find(folderDownload) do |fx|. The basic grind
  puts "\n7. (#{lineNum}). Copying and renaming finished. #{i} gpx files copied to #{folderNew}.\n" 
  puts "\n160. newFiles: #{newFiles}.\n    Not exactly the same as newFiles below."
  return newFiles   
end
def copyMotionX ( newFiles , baseFolderGPX , folderDownload ) puts "\n6. (165). Copying MotionX gpx files\n from #{folderDownload} to Massaged Folder and \nadding to newFiles, the list of files to be processed." i = 0 folderNew = "167. folderDownload: #{folderDownload}" today = Time . now . strftime ( "%Y%m%d" ) puts Find . find ( folderDownload ) do | fx | next if ! File . file? ( fx ) Find . prune if File . extname ( fx ) != '.gpx' puts "\n174. fx: #{fx}. \nFile.basename(fx): \n #{File.basename(fx)}" dotDate = motionXdate ( fx ) puts "#{lineNum}. dotDate: #{dotDate}" yearFile = dotDate [ 0 .. 3 ] dateFile = dotDate . gsub ( "." , "" ) puts "dateFile: #{dateFile}" puts folderNew = "#{baseFolderGPX}#{yearFile} Massaged" newBasename = "#{dotDate} - #{File.basename(fx)}" if today == dateFile fileshortnew = newBasename + ".TEMP" fnew = "#{folderNew}/#{fileshortnew}.gpx" puts "201.. fnew: #{fnew}." else fnew = "#{folderNew}/#{newBasename}.gpx" end puts "207.. fx: #{fx}. " if ! File . exists? ( fnew ) puts "209.. fnew: #{fnew}. " newFiles << fnew FileUtils . cp ( fx , fnew ) i = + 1 end end puts "\n7. (#{lineNum}). Copying and renaming finished. #{i} gpx files copied to #{folderNew}.\n" return newFiles end
Copy and rename files from Year Downloads to Year Massaged folder and create list of those new files
Copy and rename files from Year Downloads to Year Massaged folder and create list of those new files
# puts "166. fx: #{fx}. File.file?(fx): #{File.file?(fx)}. " # the directory we're looking in is added to the fx list, so skip it. # Was  Find.prune if … which didn't work # get errors trying to process other files on card. # Establish file name # 2015.03.19 MotionX changed file naming and they don't come with date first anymore, so will have to extract date from file.  # Read first <time> and set it to firstTime or  # then extract and set dotTime to be added to beginning of filename while keeping the rest of the filenam #REDO THIS AS NEEDED # puts "185. yearFile: #{yearFile}" # puts "188. folderNew:" # MIGHT MOVE THIS FROM THE TWO DEFS #  # puts "\n\n184. newBasename: #{newBasename}" # if today==File.basename(fx, ".TEMP.gpx") # puts "\n194. today: #{today}. dateFile: #{dateFile}" # puts "193.. fx: #{fx}" # all but today's file # puts "204. fnew: #{fnew}." # today==. Add TEMP to today's files # !File.exists?(fnew). add to newFiles  # Find.find(folderDownload) do |fx|. The basic grind # puts "\n160. newFiles: #{newFiles}.\n    Not exactly the same as newFiles below."
newFiles
<not_specific>
baseFolderGPX
<not_specific>
folderDownload
<not_specific>