如题

解决方案 »

  1.   

    盘符一样的话直接调这个函数Directory.Move(@"d:\p\1\a", @"d:\j\c");还需要做点额外工作,确保原始文件夹"d:\p\1\a" 和 目标文件夹的父目录 "d:\j"已存在,并确保"d:\j\c"不存在
      

  2.   

    using System;
    using System.IO;class Test 
    {
        public static void Main() 
        {
            string path = @"d:\p\1\a";
            string path2 = @"d:\j\c";
            try 
            {
                using (FileStream fs = File.Create(path)) {}
                // Ensure that the target does not exist.
                if(File.Exists(path2))
                File.Delete(path2);            // Copy the file.
                File.Copy(path, path2);
                Console.WriteLine("{0} copied to {1}", path, path2);            // Try to copy the same file again, which should fail.
                File.Copy(path, path2);
                Console.WriteLine("The second Copy operation succeeded, which was not expected.");
            }         catch (Exception e) 
            {
                Console.WriteLine("Double copying is not allowed, as expected.");
                Console.WriteLine(e.ToString());
            }
        }
    }
      

  3.   


    并确保"d:\j\c"不存在
    存在的话怎么处理关系到产品交互,不是一个纯技术问题。
      

  4.   

    if (tb_font.Text != string.Empty)
                {
                    if (File.Exists(this.tb_font.Text.Trim()))
                    {
                        string p1 = @tb_font.Text;
                        string p2 = @pathfont;
                        string p2a = File.GetAttributes(p2).ToString();
                        if (p2a != "Archive")
                        {
                            File.SetAttributes(p2, FileAttributes.Archive);
                        }
                        File.Copy(p1, p2, true);
                        MessageBox.Show(p1 + "  到  " + p2 + "  替换成功");
                    }
                    else
                    {
                        toolTip1.Show("字体不存在,请重新选择!", tb_font, 2000);
                    }
                    
                }
                else
                {
                    toolTip1.Show("请选择字体!", tb_font, 2000);
                }用copy把 复制. 改move 应该也可以..
    这是以前一个小东西..的关键代码..
    你这个问题一是考虑目录存在 二是考虑文件存在 做下判断就好了 三是考虑文件权限问题
    可能我的代码很菜 不过你应该可以改出更好的代码..
      

  5.   


    并确保"d:\j\c"不存在
    是的,谢谢指点!