【发布时间】:2019-01-02 23:06:38
【问题描述】:
我正在使用 C#,使用 XCOPY。我有将完整目录复制到另一个目录的方法:
public static void ProcessXcopy(string SolutionDirectory, string TargetDirectory)
{
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
//Give the name as Xcopy
startInfo.FileName = "xcopy";
//make the window Hidden
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//Send the Source and destination as Arguments to the process
startInfo.Arguments = "\"" + SolutionDirectory + "\"" + " " + "\"" + TargetDirectory + "\"" + @" /e /y /I /B";
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch (Exception exp)
{
throw exp;
}
}
我想知道成功复制到另一个目录后是否有办法删除源目录。
【问题讨论】:
-
XCopy 用于从命令行使用。为什么要使用它而不是直接从代码中执行此操作?