Hundreds of images were taken by CCD in batches, named 1.bmp,2.bmp,3.bmp ... , in order, because some of the images are blurred or not conforming to the processing
Conditions, I manually remove it, so I just mentioned the problem, now a large number of picture file name is not continuous, with MATLAB processing inconvenient. So I wrote a C # applet to automatically arrange the images.
I am a rookie, hehe, if you master has a better solution and algorithm, a lot of advice ah. 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//Automatic renaming
7 namespace Renamebmp
8 {
9 Class Program
10 {
One static void Main (string[] args)
12 {
INT-1; Start picture number
int last = 301; End Picture Number
int temp;
String path1; Find the first empty position
Path2 string; The smallest numbered picture file path after finding the empty location
int count = 0; Number of pictures
String temppath = "";
for (int k = i k <= last; k++)
21 {
TempPath = "F:\test6\" + k.tostring () + ". bmp";
if (file.exists (TempPath))
count++;
25}
for (int i = i <= count; i++)
27 {
temp = i + 1;
path1 = "F:\test6\" + i.tostring () + ". bmp";
if (! File.exists (path1))
31 {
path2 = "F:\test6\" + temp. ToString () + ". bmp";
a while (! File.exists (path2))
34 {
temp++;
if (temp = last)
37 {
path2 = "F:\test6\" + last. ToString () + ". bmp";
The break;
40}
path2 = "F:\test6\" + temp. ToString () + ". bmp";
42}
File.move (path2, path1); Rename using the Move method
44}
45}
MessageBox.Show ("Sorting finished, sorted after the number of pictures as" +count. ToString ());
47}
48}
49}