文件改名代码 string filen="baidu.exe"麻烦哪位大侠帮我用C#语言 把这个文件改名 谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://blog.163.com/henrytown@126/blog/static/5320530520077279415737/ //获取当前路径下全部文件名 String[]files = Directory.GetFiles(Environment.CurrentDirectory); foreach(Stringfilename in files) { //最后一个"\" intlastpath = filename.LastIndexOf("\\"); //最后一个"." intlastdot = filename.LastIndexOf("."); // 纯文件名字长度 intlength = lastdot-lastpath-1; // 文件目录字符串 xx\xx\xx\ Stringbeginpart = filename.Substring(0, lastpath+1); // 纯文件名字 Stringnamenoext = filename.Substring(lastpath+1, length); // 扩展名 Stringext = filename.Substring(lastdot); if(length< 3) { // 补齐为3位,组成新的文件名 Stringnamenew; if(length== 1) namenew= "00" + namenoext; else namenew= "0" + namenoext; Stringfullnewname = beginpart + namenew + ext; // 改名 File.Move(filename,fullnewname); //log this.listBoxLog.Items.Add(namenoext+ "--->" + namenew); this.listBoxLog.SelectedIndex= this.listBoxLog.Items.Count - 1; } FileSystem.Rename 方法命名空间:Microsoft.VisualBasic程序集:Microsoft.VisualBasic(在 microsoft.visualbasic.dll 中) 楼上,File有这个方面吗?看看MSDN 直接用File.Move(要改名的文件路径及其名称,改之后的路径及其名称)相当于剪切 Update 无法找到 TableMapping['Table'] 或 DataTable“Table” 取出list内时间范围里面的集合 数据转换 文字内容格式化后(色彩,字型等等),存入数据库和从数据库读取出,怎样保持格式不变? 如何将一个数组加入到另一个数组 用.NET能否实现WORD文件的合并 我实在没分了:如何用DllImport调用返回结构指针的函数? 如何在C#程序中打开PDF,OFFICE,WMV,JPG等文件? 怎么检测软件是否被修改过 硬盘序列号,如何取得? .net 2.0与.net 3.5不兼容,高手们指点 请教怎样实现程序运行自动缩小到系统托盘里?
//获取当前路径下全部文件名
String[]files = Directory.GetFiles(Environment.CurrentDirectory);
foreach(Stringfilename in files)
{
//最后一个"\"
intlastpath = filename.LastIndexOf("\\");
//最后一个"."
intlastdot = filename.LastIndexOf(".");
// 纯文件名字长度
intlength = lastdot-lastpath-1;
// 文件目录字符串 xx\xx\xx\
Stringbeginpart = filename.Substring(0, lastpath+1);
// 纯文件名字
Stringnamenoext = filename.Substring(lastpath+1, length);
// 扩展名
Stringext = filename.Substring(lastdot);
if(length< 3)
{
// 补齐为3位,组成新的文件名
Stringnamenew;
if(length== 1)
namenew= "00" + namenoext;
else
namenew= "0" + namenoext;
Stringfullnewname = beginpart + namenew + ext;
// 改名
File.Move(filename,fullnewname); //log
this.listBoxLog.Items.Add(namenoext+ "--->" + namenew);
this.listBoxLog.SelectedIndex= this.listBoxLog.Items.Count - 1;
}
程序集:Microsoft.VisualBasic(在 microsoft.visualbasic.dll 中)
楼上,File有这个方面吗?看看MSDN