如何批量改文件名。(自己写了一个,大家参考)nautilus右键菜单的v3。
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
- firehare
- 帖子: 2625
- 注册时间: 2005-04-10 16:54
- 来自: 温州大学
- 联系:
-
- 帖子: 3025
- 注册时间: 2005-05-07 23:57
- 联系:
如何一次就重新命名整个目录下的文件?
http://www.ubuntu.org.cn/support/docume ... /guide/mvb
http://www.ubuntu.org.cn/support/docume ... /guide/mvb
独自看一看大海
总想起身边走在路上的朋友
Lenovo E290-420[Celeron-M420/256M/60G/Intel GMA950]
总想起身边走在路上的朋友
Lenovo E290-420[Celeron-M420/256M/60G/Intel GMA950]
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
一次就重新命名整个目录下的文件!也太那个了吧。yongyi 写了:如何一次就重新命名整个目录下的文件?
http://www.ubuntu.org.cn/support/docume ... /guide/mvb
不人性
● 鸣学
-
- 帖子: 3025
- 注册时间: 2005-05-07 23:57
- 联系:
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
发了狠,自己写了一个。
我知道可以加到~/.gnome2/nautilus-scripts做脚本。自动把选择的文件批量改名字。用zenity作第二参数的输入。现在要带崽崽了。有时间再搞。
一句话,bash麻烦。想用c。
以下执行状态显示。
一句话,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: 发了狠,自己写了一个。
楼主如果在论坛用C开个小项目的话,我跟着你拼命干下去......!eexpress 写了:我知道可以加到~/.gnome2/nautilus-scripts做脚本。自动把选择的文件批量改名字。用zenity作第二参数的输入。现在要带崽崽了。有时间再搞。
一句话,bash麻烦。想用c。
顺便练练手!
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
- yonsan
- 帖子: 887
- 注册时间: 2005-07-01 18:56
- 来自: 广州市
- yonsan
- 帖子: 887
- 注册时间: 2005-07-01 18:56
- 来自: 广州市
楼主是想用C搞个批量改文件名的小项目?
我在ubuntu下还未成功编译过这个gtk+入门的示例:
hellogtk.c
makefile
不知楼主的gtk开发环境配置好未? 如果成功了请介绍一下经验。
现在上网用ubuntu系统, 编程用lfs系统! 在两个系统中换来换去也不是滋味!!
哦对了,以上这个示例在lfs下是成功编译的!
我在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;
}
代码: 全选
###############################################################################
#编译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)
现在上网用ubuntu系统, 编程用lfs系统! 在两个系统中换来换去也不是滋味!!
哦对了,以上这个示例在lfs下是成功编译的!
- 附件
-
- hellogtk.png (1.37 KiB) 查看 3323 次
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙