string app_path_temp = App.App_Path + "\\";
string sourcePath = System.IO.Path.Combine(app_path_temp, "Dump\\SID\\temp\\", filename1);
string destPath = System.IO.Path.Combine(app_path_temp, "Training\\", fileBaseName, "\\", filename1);
File.Copy(sourcePath, destPath, true);
当我将文件夹路径设置为“FolderName1 \ FolderName2 \ FolderName3 \ ApplicationPath”时,代码工作正常。但是,当路径类似于“文件夹名称1 \文件夹名称2 ...”时,它不起作用。
显示错误“无法找到文件 文件夹名称1 \文件夹名称2 ...”
答案 0 :(得分:1)
在C#6中,你可以将$和@前缀同时应用于同一个字符串,这意味着"插入这个逐字字符串",希望这对你有用:
string sourcePath = $@"{App.App_Path}\Dump\SID\temp";
string destPath = $@"{App.App_Path}\Training\{fileBaseName}";
// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, filename1);
string destFile = System.IO.Path.Combine(destPath, filename1);
File.Copy(sourceFile, destFile, true);