asp.net file Batch rename program

Source: Internet
Author: User

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}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.