这是来自 Microsoft 的代码示例,具有不同的文件位置,但无法正常工作:
string fileName = "test1.txt";
string sourcePath = @"C:\";
string targetPath = @"C:\Test\";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(sourceFile, destFile, true);
它找不到源文件。如果我设置一个断点,这就是我得到的:
args {string[0]} string[]
fileName "test1.txt" string
sourcePath "C:\\" string
targetPath "C:\\Test\\" string
sourceFile "C:\\test1.txt" string
destFile "C:\\Test\\test1.txt" string
因此,即使使用逐字字符串,它看起来也将反斜杠加倍。(毫无疑问,我在 C 中有一个 test1.txt 文件:)有什么想法吗?谢谢!