在C#代码中,定义关于路径的字符串变量时,字符串前要加@
[code] if (!Directory.Exists(@\"E:\\test\\backdata\")){Directory.CreateDirectory(@\"E:\\test\\backdata\");}string path = @\"E:\\test\\testdata\\\" + str + \"\";string path2 = @\"E:\\test\\backdata\\\" + str + \"\";FileInfo fi1 = new FileInfo(path);FileInfo fi2 = new FileInfo(path2);try{// Create the source file.// using (FileStream fs = fi1.Create()) { }//Ensure that the target file does not exist.if (File.Exists(path2)){fi2.Delete();}//Copy the file.ffi1.CopyTo(path2); //文件从path复制到path2,同时删除路径path的文件richTextBox1.Text += String.Format(\"\\n{0} 复制到 {1}.\", path, path2);File.Delete(path);richTextBox1.Text += \"\\npath删除成功\";
或者将\\改为\\\\,
[code]string path = \"E:\\\\test\\\\testdata\\\\\" + str + \"\";
爱站程序员基地
![(原创)[C#] 一步一步自定义拖拽(Drag&Drop)时的鼠标效果:(一)基本原理及基本实现-爱站程序员基地](https://aiznh.com/wp-content/uploads/2022/07/20220721231016-62d9dcd85c40b-220x150.gif)

