难,难,难,如何实现批量改名!!!
现在我遇到一个对我这个菜鸟来说巨难的问题:
d:\>myfiles目录下面有大量的doc文件,而且都是按照时间来命名的,比如 200407120925.doc,现在我需要把其中的07改成10,如何做啊?
也就是说,通过asp.net + C# 能实现吗?
就是我的程序需要去遍历myfiles文件夹,通过for循环去逐个修改名字,其实应该不难的,大侠给我个思路,如果有程序更好!
谢谢啊,急!!!
问题点数:0、回复次数:3Top
1 楼yellowhwb(天の羽)回复于 2004-12-01 15:02:56 得分 0
递归遍历文件夹里的文件然后改名.
private void getFiles(String sourcePath)
{
try
{
DirectoryInfo Folder = new DirectoryInfo(sourcePath);
foreach(FileInfo NextFile in Folder.GetFiles())
{
//NextFile改名操作
}
foreach(DirectoryInfo NextFolder in Folder.GetDirectories())
{
getFiles(NextFolder.FullName);
}
}
catch(Exception ex)
{
throw ex;
}
}Top
2 楼ty34565(我爱茉莉花)回复于 2004-12-01 15:25:29 得分 0
string path="c:\\myfile";
string [] files=System.IO.Directory.GetFiles(path,"*.doc");
string destfile=null;
foreach(string file in files)
{
if(file.IndexOf("07")>-1)
{
destfile=file.Replace("07","10");
if (System.IO.File.Exists(path+"\\"+destfile))
System.IO.File.Delete(path+"\\"+destfile);
System.IO.File.Move(path+"\\"+file, path+"\\"+destfile);
}
}
这样可以吗Top
3 楼linlinunix(铁匠)回复于 2004-12-01 16:38:15 得分 0
string path="c:\\myfile";
string [] files=System.IO.Directory.GetFiles(path,"*.doc");
string destfile=null;
foreach(string file in files)
{
if(file.IndexOf("07",4)>-1) //避免日期或编号中也有07/////////
{
destfile=file.Replace("07","10");
if (System.IO.File.Exists(path+"\\"+destfile))
System.IO.File.Delete(path+"\\"+destfile);
System.IO.File.Move(path+"\\"+file, path+"\\"+destfile);
}
}
Top




