Asp.net file batch rename Program
Several hundred images were taken in batches using CCD, named as 1.bmp, 2.bmp, and 3.bmp... , In order, because some images are blurred or non-conforming
Condition, I manually remove it, so with the problem mentioned just now, a large number of image file names are not continuous, and it is not convenient to use Matlab for processing. So I wrote a C # applet to automatically arrange images.
I'm a cainiao. If you have better solutions and algorithms, please advise me a lot. The Code is as follows:
1 using System;
2 using System. Collections. Generic;
3 using System. Text;
4 using System. IO;
5 using System. Windows. Forms;
6 // automatically rename
7 namespace renamebmp
8 {
9 class Program
10 {
11 static void Main (string [] args)
12 {
13 int first = 1; // start Image number
14 int last = 301; // end image number
15 int temp;
16 string path1; // The first empty position found
17 string path2; // the path of the image file with the minimum serial number after the empty position found
18 int count = 0; // number of images
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); // use the move method to rename
44}
45}
46 MessageBox. Show ("after sorting, the number of images after sorting is" + count. ToString ());
47}
48}
49}