public Rename(string sourceFile, string destinyFile)
if(System.IO.File.Exist(sourceFile))
{
    try
    {
        System.IO.File.Move(sourceFile, destinyFile);
    }
    catch(Exception e)
    {
        Console.WriteLine(e.Message);
    }
}
或者先File.Copy(sourceFile, destinyFile);
再File.Delete(sourceFile);
参考ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemiofileclasstopic.htm

解决方案 »

  1.   

    咔咔, 代码帖少了一部分
    public Rename(string sourceFile, string destinyFile)
    {
        if(System.IO.File.Exist(sourceFile))
        {
            try
            {
                System.IO.File.Move(sourceFile, destinyFile);
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        else
        {
            Console.WriteLine("源文件{0}不存在!", sourceFile);
        }
    }
      

  2.   

    谢谢 superct(圣堂·天子) :我要重新修改名称的文件大概有80万个,你的代码效率是不是有点低?可行性不好吧。因为我想写一快速重命名的工具。
      

  3.   

    我的思路是这样,你看看怎么样Process proc = new Process();
    proc.StartInfo.FileName="ren";
    proc.StartInfo.CreateNoWindow=true;
    proc.StartInfo.Arguments="xxx.doc yyy.txt";
    proc.Start();
      

  4.   

    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfsystemdirectoryservicesdirectoryentryclassctortopic.htm它有个DirectoryEntry.Rename 方法试试!
      

  5.   

    private void button1_Click(object sender, System.EventArgs e)
    {
         string path = @"D:\test";
    string[] spacifyFile=Directory.GetFiles(path);
        int i=0;
    foreach(string tempFile in spacifyFile)
    {

        i++;
    System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
    Info.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
    Info.FileName = "cmd.exe";
    string renameStr =  @"/c rename "+tempFile+" "+i.ToString()+"eeee.txt";
    Info.Arguments =renameStr;
    //Info.RedirectStandardOutput = true;
    //Info.UseShellExecute = false;
    System.Diagnostics.Process.Start(Info);

    }

    }
    记得加名字空间:using System.Diagnostics;
      

  6.   

    楼上的学过FAT 表吗?知道那是什么吗?呵呵,就是使用 file.move它操作的源和目标对象如果是同一目录并不是移动而是直接修改分配表中的文件名并不会改动物理偏移,呵呵,你自己用diskmon 或filemon 试试就知道了
      

  7.   

    是否可以用直接访问物理fat表的方式来修改呀,那样做的效率可能要高一点,因为直接跳过了操作系统,只不过对于编程者的要求比较高,更多的是,要是遇到了ntfs格式的分区,好像那方面的资料很少呀,顺便说一句,谁有ntfs格式的资料一定要放上来哦
      

  8.   

    to snewxf(心疤) 俺不是说你,楼上是指上面的,说楼主几位明明在原贴已经说了用move 这里却非要开贴叫人避开move 用其它方法逼的楼上几位想出各种歪点子,哈哈。。
      

  9.   

    补充:同一目录:改的是FAT 表文件名
    同一逻辑盘:改的是FAT 表文件名和偏移位置
    源和目标不在同一盘:重写所有内容(理论上来说比复制还慢)