如何批量改文件名。(自己写了一个,大家参考)nautilus右键菜单的v3。

OOo,TeX,KO,ABI,GIMP,Picasa,ProE,QCAD,Inkscape,Kicad,Eagle
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

如何批量改文件名。(自己写了一个,大家参考)nautilus右键菜单的v3。

#1

帖子 eexpress » 2005-08-29 16:43

mv??
上次由 eexpress 在 2005-10-11 19:59,总共编辑 4 次。
● 鸣学
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#2

帖子 firehare » 2005-08-29 16:56

批量这种说法就有点不妥,如何批量呢?按照什么规律来批量修改呢?所以我认为一定是会要用上脚本的。光是一个mv不足以完成批量这一任务的
我心无畏,源自于我心无知。
图片
yongyi
帖子: 3025
注册时间: 2005-05-07 23:57
联系:

#3

帖子 yongyi » 2005-08-29 22:54

如何一次就重新命名整个目录下的文件?
http://www.ubuntu.org.cn/support/docume ... /guide/mvb
独自看一看大海
总想起身边走在路上的朋友
Lenovo E290-420[Celeron-M420/256M/60G/Intel GMA950]
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#4

帖子 eexpress » 2005-08-29 23:09

yongyi 写了:如何一次就重新命名整个目录下的文件?
http://www.ubuntu.org.cn/support/docume ... /guide/mvb
一次就重新命名整个目录下的文件!也太那个了吧。







不人性
● 鸣学
yongyi
帖子: 3025
注册时间: 2005-05-07 23:57
联系:

#5

帖子 yongyi » 2005-08-29 23:56

脚本
独自看一看大海
总想起身边走在路上的朋友
Lenovo E290-420[Celeron-M420/256M/60G/Intel GMA950]
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

发了狠,自己写了一个。

#6

帖子 eexpress » 2005-08-30 21:17

我知道可以加到~/.gnome2/nautilus-scripts做脚本。自动把选择的文件批量改名字。用zenity作第二参数的输入。现在要带崽崽了。有时间再搞。
一句话,bash麻烦。想用c。

代码: 全选

#!/bin/bash
clear
if(("$#"<2));then
	echo '---------------------------------------------------------'
	echo '    用法: batchrename 2005*.jpg Zh_%.jpg'
	echo '    第一个参数符合ls使用的正规表达式。'
	echo '    第二个参数中用%号表示递增的序号。'
	echo '    智能处理了原文件名符合修改后条件的情况,直接不处理。'
	echo '    显示为“不需要修改”。'
	echo '    最关键的一个地方要感谢x.f的帮助才完成。'
	echo '    由于"My file"和"My private file"这样的空格名字'
	echo '    无法区别,所以没有处理空格文件,简单的显示为“不存在”。'
	echo '    第一次写bash,玩了很久才搞好。'
	echo '    2005年08月30日 eexpress'
	echo '---------------------------------------------------------'
	exit 1
fi
number=0
num=0
already_exist=""
for I in $@
do
	((num++))
	if [ ! -f $I ]; then
		if [ "${!#}" = "$I" ]; then exit; fi		
		echo "第$num个文件 $I 不存在。"
		continue
	fi
	echo -n "$I -> "
	tmp=`echo $already_exist|grep "$I"`
	if [ "$tmp" != "" ]; then
		echo "不需要修改"
		continue
	fi
	J=`echo ${!#} | sed s/%/$number/`
	while [ -e $J ]
	do
		already_exist="$already_exist $J"
		((number++))
		J=`echo ${!#} | sed s/%/$number/`
	done
	echo $J
	mv "$I" "$J"
	((number++))
done
exit 0
#end
以下执行状态显示。

代码: 全选

exp@eexpress-ubuntu:~$ ls
=                      2101.jpg         batchrename.sh~*  pic/
20050518111040439.gif  66 8.gif         COM_2.gif         sh-test~*
20050518111052514.gif  9                Desktop/          step0
20050518111101508.gif  =9               doc/              step1
20050518111117834.gif  app/             install/          what_3.gif
20050518111127373.gif  batchrename.sh*  mvb*              使用 sed 编辑器.txt~
exp@eexpress-ubuntu:~$ sh batchrename.sh *.gif what_%.gif
20050518111040439.gif -> what_0.gif
20050518111052514.gif -> what_1.gif
20050518111101508.gif -> what_2.gif
20050518111117834.gif -> what_4.gif
20050518111127373.gif -> what_5.gif
第6个文件 66 不存在。
第7个文件 8.gif 不存在。
COM_2.gif -> what_6.gif
what_3.gif -> 不需要修改
exp@eexpress-ubuntu:~$ ls
=         app/              install/   step1       what_4.gif
2101.jpg  batchrename.sh*   mvb*       what_0.gif  what_5.gif
66 8.gif  batchrename.sh~*  pic/       what_1.gif  what_6.gif
9         Desktop/          sh-test~*  what_2.gif  使用 sed 编辑器.txt~
=9        doc/              step0      what_3.gif
exp@eexpress-ubuntu:~$
上次由 eexpress 在 2005-08-31 22:32,总共编辑 1 次。
● 鸣学
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

Re: 发了狠,自己写了一个。

#7

帖子 yonsan » 2005-08-30 22:10

eexpress 写了:我知道可以加到~/.gnome2/nautilus-scripts做脚本。自动把选择的文件批量改名字。用zenity作第二参数的输入。现在要带崽崽了。有时间再搞。
一句话,bash麻烦。想用c。
楼主如果在论坛用C开个小项目的话,我跟着你拼命干下去......!
顺便练练手! :o
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#8

帖子 eexpress » 2005-08-30 22:40

linux这边gcc都找不到。刚开始摸索。要不我才不会花大时间搞bash。
等我把编译器这些基本的搞好以后。我会研究的。
● 鸣学
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

#9

帖子 yonsan » 2005-08-30 23:53

eexpress 写了:linux这边gcc都找不到。刚开始摸索。要不我才不会花大时间搞bash。
等我把编译器这些基本的搞好以后。我会研究的。
就这三个命令可以有个基本的gcc环境:

代码: 全选

apt-get install automake
apt-get install gcc
apt-get install g++
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#10

帖子 eexpress » 2005-08-31 1:25

已经安装了Anjuta和Glade。有时间就搞。非常漂亮。
● 鸣学
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

#11

帖子 yonsan » 2005-08-31 1:38

eexpress 写了:已经安装了Anjuta和Glade。有时间就搞。非常漂亮。
看样子是采用gtk+开发库了!
还好,gtk+还有点基础,qt方面就没经验了!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#12

帖子 eexpress » 2005-08-31 14:03

要不就安装bulk rename的界面先做一个实验一下。
● 鸣学
头像
yonsan
帖子: 887
注册时间: 2005-07-01 18:56
来自: 广州市

#13

帖子 yonsan » 2005-08-31 15:08

:o 楼主是想用C搞个批量改文件名的小项目?

我在ubuntu下还未成功编译过这个gtk+入门的示例:
hellogtk.c

代码: 全选

#include <gtk/gtk.h>

/* This is a callback function. The data arguments are ignored
 * in this example. More on callbacks below. */
static void hello( GtkWidget *widget,
                   gpointer   data )
{
    g_print ("Hello World\n");
}

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    /* If you return FALSE in the "delete_event" signal handler,
     * GTK will emit the "destroy" signal. Returning TRUE means
     * you don't want the window to be destroyed.
     * This is useful for popping up 'are you sure you want to quit?'
     * type dialogs. */

    g_print ("delete event occurred\n");

    /* Change TRUE to FALSE and the main window will be destroyed with
     * a "delete_event". */

    return TRUE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
    GtkWidget *button;
    
    /* This is called in all GTK applications. Arguments are parsed
     * from the command line and are returned to the application. */
    gtk_init (&argc, &argv);
    
    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    /* When the window is given the "delete_event" signal (this is given
     * by the window manager, usually by the "close" option, or on the
     * titlebar), we ask it to call the delete_event () function
     * as defined above. The data passed to the callback
     * function is NULL and is ignored in the callback function. */
    g_signal_connect (G_OBJECT (window), "delete_event",
		      G_CALLBACK (delete_event), NULL);
    
    /* Here we connect the "destroy" event to a signal handler.  
     * This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete_event" callback. */
    g_signal_connect (G_OBJECT (window), "destroy",
		      G_CALLBACK (destroy), NULL);
    
    /* Sets the border width of the window. */
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    /* Creates a new button with the label "Hello World". */
    button = gtk_button_new_with_label ("Hello World");
    
    /* When the button receives the "clicked" signal, it will call the
     * function hello() passing it NULL as its argument.  The hello()
     * function is defined above. */
    g_signal_connect (G_OBJECT (button), "clicked",
		      G_CALLBACK (hello), NULL);
    
    /* This will cause the window to be destroyed by calling
     * gtk_widget_destroy(window) when "clicked".  Again, the destroy
     * signal could come from here, or the window manager. */
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (gtk_widget_destroy),
                              G_OBJECT (window));
    
    /* This packs the button into the window (a gtk container). */
    gtk_container_add (GTK_CONTAINER (window), button);
    
    /* The final step is to display this newly created widget. */
    gtk_widget_show (button);
    
    /* and the window */
    gtk_widget_show (window);
    
    /* All GTK applications must have a gtk_main(). Control ends here
     * and waits for an event to occur (like a key press or
     * mouse event). */
    gtk_main ();
    
    return 0;
}
makefile

代码: 全选

###############################################################################
#编译gtk+ 程序的makefile
#用于测试ubuntu下gtk+的开发环境配置情况。
#

##############
#GCC工具
GCC=gcc
#源文件
INPUT=hellogtk.c
#目标程序
OUTPUT=hellogtk
#C编译选项
CFLAGS=-Wall -g
#GTK+编译选项
GTK_FLAGS=`pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`


##############
#TOP_TARGET
all:
	$(GCC) $(CFLAGS) $(INPUT) -o $(OUTPUT) $(GTK_FLAGS)
不知楼主的gtk开发环境配置好未? 如果成功了请介绍一下经验。
现在上网用ubuntu系统, 编程用lfs系统! 在两个系统中换来换去也不是滋味!!
哦对了,以上这个示例在lfs下是成功编译的!
附件
hellogtk.png
hellogtk.png (1.37 KiB) 查看 3322 次
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#14

帖子 eexpress » 2005-08-31 17:02

:lol: 还没有那么快。今天凌晨才装的环境。
今天刚带崽崽到寺中看菩萨。还没来的赢开始。
晚上先试glade。应该到anjuta的关系容易清楚。
搞好了通知。
● 鸣学
zengsun
帖子: 334
注册时间: 2005-05-17 14:45

#15

帖子 zengsun » 2005-09-01 9:24

我在linux下也没有成功编译GTK+的程序!
总是报告找不到头文件。
现在还是在学java!
回复