I'm making a program to rename files based on the date/time they were
taken.  My camera can take 5 fps, so I want to be able to handle
pictures taken at the same time (since the exif data isn't exact to less
than a second)

this is what I have so far:

---------code---------------

require('rubygems')
require('mini_exiftool')
require('LIB.BBI.rb')


def toBase36(num)
  letter='A'
  if num<10
    num36 = num.to_s
  else
    while num>10
      letter = letter.succ
      num = num-1
    end
    num36=letter
  end
  return num36
end


def timecode(image)
  if MiniExiftool.new(image)['SerialNumber'] == 620315997
    owner="JD"
  end
  time = MiniExiftool.new(image)['DateTimeOriginal']
  return to_mcode(time) +'_'+ toBase36(time.strftime('%d').to_i) +
toBase36(time.strftime('%H').to_i) +
    time.strftime('%M%S')
end

def check(string)
  if FileTest.exist?(string)
    strArr = string.split('.')
    newString = strArr.first.succ+'.'+strArr.last
    check(newString)
  else
    finalString = string
  end
  return finalString
end

def renameFilesBTC(files)
  files.each do |file|
    ext = '.'+file.split('.').last
    if file == timecode(file)+ext
      puts file+' Already Renamed'
      newName = file
    elsif file != timecode(file)+ext &&
FileTest.exist?(timecode(file)+ext)
      puts "Mulitple Files Same Time"
      newName = check(timecode(file)+'1'+ext)
    else
      puts "Rename"
      newName = timecode(file)+ext
    end
    File.rename(file , newName)
  end
end

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

I'm testing with 3 pictures taken at the same time (actually, 3 copies
of one picture).
The first two rename fine, but the third raises

------------------------------------
TypeError: cannot convert nil into String
        from ./renameByDateTime.rb:54:in `rename'
        from ./renameByDateTime.rb:54:in `renameFilesBTC'
        from ./renameByDateTime.rb:42:in `each'
        from ./renameByDateTime.rb:42:in `renameFilesBTC'
        from (irb):3
---------------------------------------

For some reason, check() returns nil for the third image, and I can't
see why it would do that.
-- 
Posted via http://www.ruby-forum.com/.