Created
September 5, 2014 19:10
-
-
Save omphe/0ceff5c293c2954b9d6c to your computer and use it in GitHub Desktop.
GoPro timelapse renamer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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