文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>把当前目录下的所有文件名由大写(或小写)字母改为小写

把当前目录下的所有文件名由大写(或小写)字母改为小写

时间:2008-04-19  来源:sdccf

作者:lg   来自:www.china-lg.com

#! /bin/sh
# Usage: ./low.sh <-l | -u> <target_directory>

#./low.sh -l directory 为全部转化为小写
#./low.sh -u directory 为全部转化为大写
#
# 第二形参必须是目录,第一形参指定-l或-u
#
if [ $# -ne 2 ] ; then
echo "Usage: ${0} <-l | -u> <target_directory>"
exit 1
fi

if [ ! -d ${2} -o "${1}" != "-l" -a "${1}" != "-u" ] ; then
echo "Usage: ${0} <-l | -u> <target_directory>"
exit 1
fi

dir=`dirname "${2}"`
cd ${dir} > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "Error: checking your ${dir}"
exit 1
fi

exec 1>/dev/null 2>&1

if [ "${1}" = "-l" ] ; then
base=`basename "${2}" | tr "[A-Z]" "[a-z]"`
else
base=`basename "${2}" | tr "[a-z]" "[A-Z]"`
fi

mv -f "`basename ${2}`" "${base}" > /dev/null 2>&1

for entry in `find ${base}`
do
before="."
for after in `echo "${entry}" | sed -e 's,/, ,g'`
do
tmp_entry="${before}/${after}"
if [ "${1}" = "-l" ] ; then
before=`echo "${tmp_entry}" | tr "[A-Z]" "[a-z]"`
else
before=`echo "${tmp_entry}" | tr "[a-z]" "[A-Z]"`
fi
mv -f "${tmp_entry}" "${before}"
done
done

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载