文件批量重命名的小程序

其实搞这个小程序只是为了更好的解决现在遇到的问题,什么问题呢?

现在在做关于图像处理的课题,用CCD批量拍摄了几百副图像,命名方式为 1.bmp,2.bmp,3.bmp。。。 ,按顺序来的,因为有些图像因为模糊或者不符合处理

条件,我手动将其剔除,于是有了刚才提到的问题,现在的大量图片文件名不连续了,用Matlab处理时不方便。于是写了个C#小程序用来自动排列图像。

我是菜鸟,呵呵,如果各位高手有更好的解决方法和算法,多多指教啊。代码如下

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
1 using System;
2   using System.Collections.Generic;
3 using System.Text;
4 using System.IO;
5 using System.Windows.Forms;
6 // 自动重命名
7 namespace renamebmp
8 {
9 class Program
10 {
11 static void Main( string [] args)
12 {
13 int first = 1 ; // 起始图片编号
14 int last = 301 ; // 结束图片编号
15 int temp;
16 string path1; // 寻找到的第一个空位置
17 string path2; // 寻找到的空位置后的最小编号图片文件路径
18 int count = 0 ; // 图片数量
19 string temppath = "" ;
20 for ( int k = first; k <= last; k ++ )
21 {
22 temppath = " F:\\test6\\ " + k.ToString() + " .bmp " ;
23 if (File.Exists(temppath))
24 count ++ ;
25 }
26 for ( int i = first; i <= count; i ++ )
27 {
28 temp = i + 1 ;
29 path1 = " F:\\test6\\ " + i.ToString() + " .bmp " ;
30 if ( ! File.Exists(path1))
31 {
32 path2 = " F:\\test6\\ " + temp.ToString() + " .bmp " ;
33 while ( ! File.Exists(path2))
34 {
35 temp ++ ;
36 if (temp == last)
37 {
38 path2 = " F:\\test6\\ " + last.ToString() + " .bmp " ;
39 break ;
40 }
41 path2 = " F:\\test6\\ " + temp.ToString() + " .bmp " ;
42 }
43 File.Move(path2, path1); // 使用move方法重命名
44 }
45 }
46 MessageBox.Show( " 排序完毕,排序后图片数量为 " + count.ToString());
47 }
48 }
49 }
50

 

转载于:https://www.cnblogs.com/spblue/archive/2010/05/05/1728344.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值