Created
May 11, 2012 22:54
-
-
Save clayalvord/2662945 to your computer and use it in GitHub Desktop.
Batch File Copy or Rename
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
#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