惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - 猫猫

SignalR 2.0 初次使用说明 解决VS2012上面EF字段说明备注没有的方法 生产百万级随机数 MyClipse DataBase Explorer 连接 ACCESS 配置说明 一个文本处理小工具(原创) C# 算法之 冒泡排序 实现数组转换为DataTable TreeView 部署到服务器上无法显示图标(失效) 仿google的suggest C# 把网页内容转为EXCEL,WORD C# 生产新闻文章分页 C# 实现页面3秒后跳转 ASPNET动态生成静态页面 正则表达式30分钟入门教程 转 正则表达式之道 转 正则表达式基础知识 转 常用正则表式 转 转 正则表达式教程 正则表达式教程 (转)
(转帖)C#批量重命名文件代码的实现
猫猫 · 2009-07-03 · via 博客园 - 猫猫

网站设计的时候.很多前台美工用PHOTOSHOP导出的图片名字是批量有规律的比如"百度.PSD"PHOTOSHOP源文件.在 PHOTOSHOP中导出所有切片文件为网页操作之后.自动会生成"百度_01.GIF,""百度_02.GIF,"...一直到"百度_99.GIF",按照一般的访问网站设计要求.尽量会要求所有的图片名称是英文字母的.所以要批量替换掉文件夹中的文件名中的"百度"两个字成为英文字母"BAIDU'的要求.

例如选择目录下有Main_11.gif,Main_12.gif,Main_13.gif...等等图片批量更新成Index_11.gif,Index_12.gif,Index_13.gif...的文件名 TextBox1里输入Main_,TextBox2里输入Index_,点按钮后选择目录,完成批量更新文件名

下面是代码

//添加文件操作空间引用 using System.Text; using System.IO;

//按钮事件代码

//使用到的控件textBox1,textBox2,listBox1,button9直接从控件箱里拖过来

private void button9_Click(object sender, System.EventArgs e)   {            string strOldFileName;    string strNewFileName;    string strOldPart=this.textBox1.Text.Trim();//重命名文件前的文件名等待替换字符串    string strNewPart=this.textBox2.Text.Trim();//重命名文件后的文件名替换字符串    string strNewFilePath;

   string strFileFolder;    //原始图片目录

   int TotalFiles=0;    DateTime StartTime = DateTime.Now; //获取开始时间  

   FolderBrowserDialog   f1=new   FolderBrowserDialog(); //打开选择目录对话框    if(f1.ShowDialog()==DialogResult.OK)      {                strFileFolder=f1.SelectedPath;     DirectoryInfo   di   =   new   DirectoryInfo(strFileFolder);       FileInfo[]   filelist   =   di.GetFiles("*.*");     int i=0;     foreach   (FileInfo   fi   in   filelist)     {               strOldFileName=fi.Name;      strNewFileName=fi.Name.Replace(strOldPart,strNewPart);      strNewFilePath=@strFileFolder+"\\"+strNewFileName;      filelist[i].MoveTo(@strNewFilePath);      TotalFiles+=1;      this.listBox1.Items.Add("文件名:"+strOldFileName + "已重命名为"+strNewFileName);      i+=1;     }    }    DateTime EndTime = DateTime.Now ;//获取结束时间    TimeSpan ts = EndTime-StartTime ;    this.listBox1.Items.Add("总耗时:"+ts.Hours.ToString() + "时"+ts.Minutes.ToString() + "分"+ts.Seconds.ToString() + "秒");

  }

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xqf222/archive/2007/07/02/1675639.aspx