--------------------------------------------------------------------
[008目录结构]
--------------------------------------------------------------------
.
|-- book-2008-08-24
|-- install.sh
|-- readme
`-- renames.sh
0 directories, 4 files
--------------------------------------------------------------------
[./readme]
--------------------------------------------------------------------
程序名称:
文件批量重命名
程序功能:
主要用于批量重命名一个文件夹下的图片
全部重新按数字编号,如1.jpg 2.jpg ...
安装方法:
./install.sh
使用说明:
1.renames.sh
运行renames.sh
……这样就行了
注意:
1.
今天发现我的图片文件夹里的图片名称乱乱的,所以想写个小脚本搞定他们
再次说明,是自己用的小脚本
有很多功能需要完善,bug多多
学习中
2.
用这个是迫不得已echo $file | sed -n -e 's/^.*\(\..*\)~$/\1/p'
因为不知为什么sed -n -e 's/^.*\(\..*\)~$/\1/p $file运行无效
总结:
1.
今天又发现一个bug
for file in *
do
if [ -f $file ] ; then
mv $file $file~
fi
done
这样的代码是不行的,应该改成
for file in *
do
if [ -f "$file" ] ; then
mv "$file" "$file"~
fi
done
比如有一个叫Gnome Nucleus.jpg的文件,最开始的那段代码是失效的 -f $file这里不能通过
--------------------------------------------------------------------
[./install.sh]
--------------------------------------------------------------------
#!/bin/sh
info="安装文件缺失,安装过程中断!"
name="批量文件重命名"
installdir="/usr/local/bin/"
if [ ! -e renames.sh ] ; then
echo "$info"
exit 1
fi
chmod +x renames.sh
cp renames.sh "$installdir"
echo "$name安装成功!"
exit 0
--------------------------------------------------------------------
[./renames.sh]
--------------------------------------------------------------------
#!/bin/sh
i=0
postfix=
rm -f *~
for file in *
do
if [ -f "$file" ] ; then
mv "$file" "$file"~
fi
done
for file in *
do
if [ -f "$file" ] ; then
postfix=`echo "$file" | sed -n -e 's/^.*\(\..*\)~$/\1/p'`
i=$(($i+1))
mv "$file" $i"$postfix"
fi
done
echo "已重命名$i个文件"
echo "程序结束"
exit 0
--------------------next---------------------
阅读(259) | 评论(0) | 转发(0) |