Skip to content

Instantly share code, notes, and snippets.

@omphe
Created September 5, 2014 19:10
Show Gist options
  • Save omphe/0ceff5c293c2954b9d6c to your computer and use it in GitHub Desktop.
Save omphe/0ceff5c293c2954b9d6c to your computer and use it in GitHub Desktop.
GoPro timelapse renamer
#!/usr/bin/env ruby
directory = ARGV[0]
ARGV.clear
puts "This will rename all *.JPG files in " + directory
print "Are you sure? [y/n]: "
confirm = gets.chomp
if confirm.eql? "y"
#let it run!
elsif confirm.eql? "n"
puts "Phew, that was close!"
exit
else
abort "Invalid response"
exit
end
if Dir.exists? directory
Dir.chdir(directory)
Dir.glob("*.JPG").sort.each_with_index do |f, index|
extension = File.extname(f)
#f_original = File.basename(f, extension)
f_renamed = index.to_s.rjust(8,"0")
File.rename(f, f_renamed + extension.downcase)
end
else
abort "No such directory!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment