最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
文件批量重命名的小程序
时间:2010-05-11 编辑:简简单单 来源:一聚教程网
条件,我手动将其剔除,于是有了刚才提到的问题,现在的大量图片文件名不连续了,用Matlab处理时不方便。于是写了个C#小程序用来自动排列图像。
我是菜鸟,呵呵,如果各位高手有更好的解决方法和算法,多多指教啊。代码如下
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";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 }
-
上一个: asp 文本文章点击统计代码
-
下一个: asp 删除数据记录并且同时删除文件图片
相关文章
- java怎么运行jar 把Java程序打包成jar文件包并执行 02-16
- ps双击载入画笔笔刷时提示该文件没有关联程序该怎么办? 01-06
- java访问.properties文件示例程序 12-18
- 用命令行将Java程序打包为jar文件 09-15
- 批量在不同的文件夹创建文件夹程序 03-09
- Global.asa文件的使用及Chat程序 01-18