我拷贝文件的时候遇到一个很奇怪的问题!
明明C:\\Users\\xxl\\Documents\\test 文件夹下什么文件都没有。但是报错说:C:\\Users\\xxl\\Documents\\test\\aa.txt已经存在。我是Win7系统。
string _localDirectory = System.Environment.CurrentDirectory.ToString();
path="C:\\Users\\xxl\\Documents\\test\\aa.txt";File.Copy(_localDirectory + "\\aa.txt", path);

解决方案 »

  1.   

    File.Copy(Path.Combine(_localDirectory ,"aa.txt"), path,true);调试查看_localDirectory 值是多少
      

  2.   

    或者在copy之前判断一把
    file.exits(path) 目标目录下文件存在则询问用户是否覆盖
    File.Copy(Path.Combine(_localDirectory ,"aa.txt"), path,true);
    否则不复制。
      

  3.   

    奇怪的问题又来!按照1楼的前辈说的,代码倒是通过了,不报错了!
    但是我C:\\Users\\xxl\\Documents\\test 文件夹下是空的!string _localDirectory = System.Environment.CurrentDirectory.ToString();
    //值是D:\MProjects\TestCopyFile\Main\bin\Debug\Config.xml
    //这个Config.xml是有的!
      

  4.   

    回复2楼 file.exits(path)也很奇怪!明明没有文件,但是返回的确实true。我删除文件夹后重新建立也不行!这是为什么!什么原理!
      

  5.   

    string _localDirectory = System.Environment.CurrentDirectory.ToString();
            string path = "C:\\aa.txt";
            File.Copy(Path.Combine(_localDirectory, "aa.txt"), path, true);
    这个是没错的 ,楼主不行重启一下机器吧呵呵