Created
February 9, 2014 20:17
-
-
Save kimchaily/8905365 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
function help() { | |
echo "batch-rename allows you to rename a bulk of filenames with RegEx" | |
echo "usage: batch-rename -r [Search] [Replace]" | |
echo "param -r: do effective renaming instead of just showing what would be done" | |
} | |
function dummyRename() { | |
echo "simulate renaming \"$1\" to \"$2\"" | |
for file in * ; do echo "simulate: $file ->" "`echo $file | sed -E "s/$1/$2/g"`" ; done | |
} | |
function rename() { | |
echo "rename \"$1\" to \"$2\"" | |
for file in * ; do mv -vf "$file" "`echo $file | sed -E "s/$1/$2/g"`" ; done | |
echo "renaming done." | |
} | |
while [[ $# > 2 ]] | |
do | |
key="$1" | |
shift | |
case $key in | |
-r|--rename) | |
RENAME=YES | |
;; | |
-e|--extension) | |
EXTENSION="$1" | |
shift | |
;; | |
-s|--searchpath) | |
SEARCHPATH="$1" | |
shift | |
;; | |
--default) | |
DEFAULT=YES | |
shift | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
# echo FILE EXTENSION = "${EXTENSION}" | |
if [[ $2 ]] | |
then | |
if [[ $RENAME ]]; then | |
rename "$1" "$2" | |
else | |
dummyRename "$1" "$2" | |
fi | |
else | |
# show help | |
help | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment