Skip to content

Instantly share code, notes, and snippets.

@clayalvord
Created May 11, 2012 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayalvord/2662945 to your computer and use it in GitHub Desktop.
Save clayalvord/2662945 to your computer and use it in GitHub Desktop.
Batch File Copy or Rename
#Batch file rename/move script
Dir.chdir '/Users/username/Pictures/'
# sets destination folder
pic_names = Dir['/Users/username/Downloads/*.{jpg,JPG}']
# sets source folder
puts 'What would you like to call this batch?'
batch_name = gets.chomp
puts
print'Downloading ' +pic_names.length.to_s+' files: '
# this is the counter.
pic_number = 1
pic_names.each do |name|
new_name = if pic_number <10
batch_name + '0' + pic_number.to_s + '.jpg'
else
batch_name + pic_number.to_s + '.jpg'
end
if File.exist?(new_name) == false
print ' .' # this is the progress bar
else
puts 'Error: ' + new_name + ' already exists'
exit
end
File.rename name, new_name
# renames the pictures
pic_number = pic_number +1
#counter increment
end
puts
puts 'Done bitches!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment