#!/bin/sh
#
# dosrename -- MSDOS-like file rename for UNIX
#
# Renames all files in a directory by extension. See the here-document below
# for details.
#
# Copyright (C) 2001.
#
# $Compile: ./dosrename$
# $Maintained at: http://www.visualco.de$
# $Author: Andreas Spindler <info@andreasspindler.de>$
# $Writestamp: 2016-04-20 12:03:52$

if [ $# -lt 2 ] || [ $# -gt 4 ]
then
    cat <<EOF
Usage:
    `basename "$0"` FROM-EXT TO-EXT [DIRECTORY] [MAXDEPTH]

Renames  all files  in  DIRECTORY  (default: ".")  from  extension FROM-EXT  to
TO-EXT. Pass  the empty  string as FROM-EXT  to append TO-EXT  to all  files in
DIRECTORY. Descend at most MAXDEPTH levels into sub-directories. The default of
1 renames in DIRECTORY only. For an unlimited depth use e.g. 999.

Examples:
    $ dosrename .jpeg .jpg ~/images
    $ dosrename 'b' 'c'                 # rename 'aab' to 'aac', 'bb' to 'bc' ...
    $ dosrename 'b' ''                  # rename 'aab' to 'aa', 'bb' to 'b'
    $ dosrename '' .tt                  # add ".tt" to all files in "."
    $ dosrename '' ''                   # no effect

EOF
else
    exit
    optfrom="$1" optto="$2" optdir="$3" optdepth=$4
    for f in `find ${optdir} -maxdepth ${optdepth:-1} -name "*$optfrom" -type f`
    do
        to="`dirname $f`/`basename $f $optfrom`$optto"
        mv -v $f $to
    done
fi

# Local Variables:
# coding: iso-8859-1-unix
# fill-column: 80
# End: