我正在使用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;
}
}我想知道,一旦源目录成功复制到另一个目录,是否有办法删除它。
发布于 2019-01-02 23:11:30
如果要粘贴.Net方法,可以在finally语句中使用Directory.Delete。第二个参数指示要删除子文件夹/文件。更多细节这里
Directory.Delete(path,true);发布于 2019-01-02 23:11:14
您可以使用robocopy而不是xcopy
robocopy from_folder to_folder files_to_copy /MOVExcopy需要.bat脚本才能拥有1行robocopy的相同功能
例如:
xcopy /D /V %1 %2
if errorlevel 0 (
del /Q %1
exit /B
)https://stackoverflow.com/questions/54014342
复制相似问题