#!/bin/bash 
# This script was written to rename .php3 to .php for all 
# files in Blazeboard. However it can also be used for any 
# other script or to change files from .php to .php3 if needed. 
# 
# It will change the extension of all files under the current 
# directory, including all files in all subdirectories, and 
# update any references in those files to reflect the new extension. 
# 
# Jonathan Haase 2/23/2001 
# 
# Extension the files currently have 
ORGEXT=php

# Extension you want to change the files to 
NEWEXT=php3 

# Get a list of all files in current directory and subdirectories 
find . > FILELIST.$$ 
grep -sv FILELIST FILELIST.$$ > FILELIST2.$$ 
grep -sv $(basename $0) FILELIST2.$$ > FILELIST.$$ 
rm FILELIST2.$$ 
# 

# Make a list of the files we want to change 
grep -s "\.$ORGEXT$" FILELIST.$$ > FILELIST 
grep -sl "\.$ORGEXT" $(grep -sv "\.$ORGEXT$" FILELIST.$$) >> FILELIST 
rm FILELIST.$$ 
# 

# work on each file 
for i in $(cat FILELIST); do 
if echo $i | grep -qs "\.$ORGEXT$" ;then 
sed -e s/"\.$ORGEXT"/"\.$NEWEXT"/g $i > $(dirname $i)/$(basename $i $ORGEXT)$NEWEXT 
rm $i 
else 
sed -e s/"\.$ORGEXT"/"\.$NEWEXT"/g $i > $i.tmp && mv $i.tmp $i 
fi 
done 
rm FILELIST 

