asp.net 檔案批量重新命名程式

來源:互聯網
上載者:User

用CCD批量拍攝了幾百副映像,命名方式為 1.bmp,2.bmp,3.bmp。。。 ,按順序來的,因為有些映像因為模糊或者不符合處理

  條件,我手動將其剔除,於是有了剛才提到的問題,現在的大量圖片檔案名稱不連續了,用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";

  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 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.