Created
November 1, 2015 23:30
-
-
Save dajo/78d11df6118c07f803f5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if [ $1 == 'help' ] || [ $1 == '?' ]; then | |
echo "Modifies extension of a group of files in current directory" | |
echo "usage: ext-modify.sh [old extension] [new extension]" | |
exit 0 | |
fi | |
OLDEXT=$1 | |
NEWEXT=$2 | |
echo "This script modifies the extension of a group of existing files." | |
if [ -z "$1" ]; then | |
echo "Enter the current extension without a period:" | |
read OLDEXT | |
echo "Enter the new extension without a period:" | |
read NEWEXT | |
else | |
echo "Using arguments..." | |
fi | |
if test -n "$(find -name '*.'$OLDEXT -print -quit)" | |
then | |
echo "Found existing file extension." | |
else | |
echo "ERROR: There are no existing files with the extension you specified." | |
exit 0 | |
fi | |
for file in *.$OLDEXT | |
do | |
mv -v "$file" "${file%.$OLDEXT}.$NEWEXT" | |
done | |
count=(*.$NEWEXT) | |
if [ ${#count[@]} == 1 ]; then | |
echo "${#count[@]}" "file had its extension modified." | |
else | |
echo "${#count[@]}" "files had their extension modified." | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment