递归遍历文件夹里的文件然后改名.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;
}
}

解决方案 »

  1.   

    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);
    }
    }
    这样可以吗
      

  2.   

    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);
    }
    }