Skip to content

Instantly share code, notes, and snippets.

@cnocon
Created February 10, 2013 19:00
Show Gist options
  • Save cnocon/4750639 to your computer and use it in GitHub Desktop.
Save cnocon/4750639 to your computer and use it in GitHub Desktop.
A small variation made to Chris Pine's batch photo re-namer example from Chapter 11 in Learning to Program.
puts 'Where do you store your screenshots? Please paste the entire directory path.'
store = gets.chomp
Dir.chdir store
pic_names = Dir["#{store}/Screen Shot*.{png}"]
puts 'What would you like to call this batch?'
batch_name = gets.chomp
puts
print "Downloading #{pic_names.length} files: "
pic_number = 1
pic_names.each do |name|
print '.' #progress bar
new_name = if pic_number < 10
"#{batch_name}0#{pic_number}.png"
else
"#{batch_name}#{pic_number}.png"
end
File.rename name, new_name
pic_number = pic_number + 1
end
puts
puts 'Donesies.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment