国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

使用C#給文件批量重命名

2023-05-09 18:58:28
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

其實(shí)搞這個(gè)小程序只是為了更好的解決現(xiàn)在遇到的問(wèn)題,什么問(wèn)題呢?現(xiàn)在在做關(guān)于圖像處理的課題,用CCD批量拍攝了幾百副圖像,命名方式為1.bmp,2.bmp,3.bmp。。。 ,按順序來(lái)的,因?yàn)橛行﹫D像因?yàn)槟:蛘卟环咸幚項(xiàng)l件,我手動(dòng)將其剔除,于是有了剛才提到的問(wèn)題,現(xiàn)在的大量圖片文件名不連續(xù)了,用Matlab處理時(shí)不方便。于是寫(xiě)了個(gè)C#小程序用來(lái)自動(dòng)排列圖像。代碼如下

  1 using System;
  2  using System.Collections.Generic;
  3 using System.Text;
  4 using System.IO;
  5 using System.Windows.Forms;
  6 // 自動(dòng)重命名
  7 namespace renamebmp
  8 {
  9     class Program
  10     {
  11         static void Main(string[] args)
  12         {
  13             int first = 1;    //起始圖片編號(hào)
  14             int last = 301; //結(jié)束圖片編號(hào)
  15             int temp;
  16             string path1; //尋找到的第一個(gè)空位置
  17             string path2; //尋找到的空位置后的最小編號(hào)圖片文件路徑
  18             int count = 0;  //圖片數(shù)量
  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("排序完畢,排序后圖片數(shù)量為 "+count.ToString());
  47         }
  48     }
  49 }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 天祝| 蛟河市| 衡阳县| 黑山县| 大冶市| 即墨市| 鲁山县| 浦县| 华池县| 乐亭县| 曲沃县| 宁武县| 南投县| 兴宁市| 新沂市| 乌鲁木齐县| 汉寿县| 石门县| 聂荣县| 依兰县| 延吉市| 巨鹿县| 缙云县| 南丰县| 监利县| 漯河市| 海盐县| 鹤庆县| 灵山县| 静安区| 灵丘县| 英超| 峨眉山市| 南郑县| 沾化县| 丹凤县| 陕西省| 曲麻莱县| 卢湾区| 盐边县| 麟游县|