最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

batch rename shell program

tmp_todo crifan 1685浏览 0评论

#! /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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.163 seconds, using 22.04MB memory