Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created April 15, 2011 16:16
Show Gist options
  • Save rafaelrinaldi/921973 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/921973 to your computer and use it in GitHub Desktop.
Helpful for when you want to change the name of a sequence of images at the same time.
# /bin/bash
#
# Helpful for when you want to change the name of a sequence of images at the same time.
#
# Author: Rafael Rinaldi (rafaelrinaldi.com)
# Since: 15/04/2011
#
path=$1
base_name=$2
count=0
if [[ ! -d $path ]]; then
echo "Invalid path!";
exit;
fi
for file in $path/*.*
do
# Keep the same extension of the original one.
extension=`echo $file | awk -F . '{print $NF}'`;
mv "$file" "$path/$base_name$count.$extension";
(( count++ ));
done
@azisaka
Copy link

azisaka commented Apr 15, 2011

in ruby

#!/usr/bin/env ruby

path = ARGV[0]
base_name = ARGV[1]

Dir["#{path}/*.*"].each_with_index do |file, index| 
   new_file = "#{File.dirname(file)}/#{base_name}#{index}#{File.extname(file)}"
   `mv #{file} #{new_file}`
end

@rafaelrinaldi
Copy link
Author

Cool! Thanks for sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment