eexpress 发表于 2005-9-1 11:51:53

写了个批量改名的脚本。nautilus中可以用的。

这是nautilus中的右键菜单脚本。仅仅需要拷贝到~/.gnome2/nautilus-scripts目录。


#!/bin/bash

if(("$#"<2));then
   zenity --info --title="用法介绍" --text=" \
在文件管理器中,选择需要修改的文件,使用右键菜单中“脚本” \
-“批量改名”。在提示窗口输入如“Zh_%.jpg”格式的信息。\
参数中用%号表示递增的序号。 \
智能处理了原文件名符合修改后条件的情况,直接不处理。 \
显示为“不需要修改”。 \
最关键的一个地方要感谢x.f的帮助才完成。 \
由于"'My file'"和"'My private file'"这样的空格名字 \
无法区别,所以没有处理空格文件,简单的显示为“不存在”。 \
2005年08月30日 eexpress \
"
   exit 1
fi
tmp=""
until [ $tmp != "" ]; do
   new_format=`zenity --title="输入新格式" --entry --text="将修改"'$#'"个文件,请输入新文件名格式。在提示窗口输入如“Zh__%.jpg”格式的信息。参数中用%号表示递增的序号。"`
   if [ "$new_format" = "" ]; then exit 1; fi #no input or cancel pressed
   tmp=`echo $new_format|grep "%"`
   if [ "$tmp" = "" ]; then
      zenity --info --title="输入错误" --text="格式中需要一个%号表示递增的文件序号。"
   fi
done

:>tmpfile
number=0
num=0
already_exist=""
for I in $@
do
   ((num++))
   if [ ! -f $I ]; then
#      if [ "${!#}" = "$I" ]; then exit; fi   
      echo "第$num个文件 $I 不是文件或者不存在。" >> tmpfile
      continue
   fi
   echo -n "$I -> " >> tmpfile
   tmp=`echo $already_exist|grep "$I"`
   if [ "$tmp" != "" ]; then
      echo "不需要修改" >> tmpfile
      continue
   fi
   J=`echo $new_format | sed s/%/$number/`
   while [ -e $J ]
   do
      already_exist="$already_exist $J"
      ((number++))
      J=`echo $new_format | sed s/%/$number/`
   done
   echo $J >> tmpfile
   mv "$I" "$J"
   ((number++))
done
zenity --info --title="修改完成" --text="`cat tmpfile`"
rm tmpfile
exit 0
#end


http://forum.ubuntu.org.cn/viewtopic.php?t=2452
_________________

bax 发表于 2005-9-9 13:02:53

那要这么复杂, 信手在命令行下写来:

for file in $(find/tmp/-name *.c);do mv $file `echo $file|sed 's/.c$/.CPP/'`;done

核心就这一句话, 你可以加几个变量满足要求

eexpress 发表于 2005-9-12 11:06:59

重名判断列。最重要了。

eexpress 发表于 2005-9-13 11:51:34

for file in $(find /tmp/ -name *.c);
我还不会那样
for file in /usr/*;
页: [1]
查看完整版本: 写了个批量改名的脚本。nautilus中可以用的。