#!/bin/sh # this renames files in a doss styleee so you can go "dosrename *.html *.htm" # to rename all files in that directory from .html to .htm. It also works # the other way: "dosrename fletch.* paul.*" t=n case $# in [01]) echo "Usage: dosRename file [ ... ] target" >&2 exit 1 ;; *) for file do case $file in *.*.*) echo "dosRename: $file: Can't have two dots" >&2 exit 3 ;; *'*'*'*'*) echo "dosRename: $file: Can't have more than one asterisk" >&2 exit 4 ;; *.'*') t=main nM=`echo "$file" | sed 's/\.\*//g'` ;; '*'.*) t=extention nE=`echo "$file" | sed 's/\*\.//g'` ;; *.*) if [ $t != 'n' ] then echo "dosRename: $file: Can't have files after target" exit 2 fi ;; *) echo "dosRename: $file: Must have a dot" >&2 exit 6 ;; esac if [ ! -f $file ] && [ $t = 'n' ] then echo "dosRename: $file: Doesn't exist" >&2 exit 5 fi done if [ $t = 'n' ] then echo "dosRename: No target" >&2 exit 7 fi esac while [ $# -gt 1 ] do if [ $t = 'extention' ] then ext=`echo "$1" | sed 's/\..*//g' mv "$1" "$ext.$nE" fi if [ $t = 'main' ] then mne=`echo "$1" | sed 's/.*\.//g' mv "$1" "$nM.$mne" fi shift done