#! /bin/sh
CUR_LEV=0
CUR_DIR=$1
ITEMS_UNDER_DIR=""
NAME_FILTER="*.bmp"
echo "this is just a script to batch rename"
echo "————————————-"
echo "Please input root dir name:"
echo "first parameter: $1"
echo "second parameter: $2"
echo "The parameter list: $@"
echo "————————————-"
echo "current dir is ${CUR_DIR}"
if [ -d ${CUR_DIR} ]
then echo "${CUR_DIR} is a dir."
else echo "${CUR_DIR} not a dir"
fi
process_dir()
{
echo "current processing dir is ${CUR_DIR}"
#cd ${CUR_DIR}
#echo "last cd result: $?"
CD_RESULT=
echo ${CD_RESULT}
if [ `cd ${CUR_DIR}` ];
then echo "dir: ${CUR_DIR} does not exist"
exit
else
echo "Successfully go int dir: ${CUR_DIR}"
fi
#find all item under a dir
echo "files under ${CUR_DIR} :"
ITEMS_UNDER_DIR=`ls`
echo ${ITEMS_UNDER_DIR}
#for each, if dir, then circlely process it
for CURR_ITEM in ${ITEMS_UNDER_DIR}; do
if [ -d ${CURR_ITEM} ]
#then process_dir
then echo "${CURR_ITEM} is a valid dir."
else
if [ -f ${CURR_ITEM} ]; then
if [ ${CURR_ITEM} = ${NAME_FILTER} ]; then
echo "current file ${FILE_NAME} matchs ${NAME_FILTER}"
#find name part and rename: ‘mv $(FILE_NAME) ‘
fi
fi
fi
#if file, if it is a bmp, rename it to name_new.bmp
#omit others
done
}
process_dir
#if [ -d $(ITEM_NAME) ]; then
# echo "$(ITEM_NAME) is a dir."
#else
#fi
转载请注明:在路上 » batch rename shell program