我正在使用XCOPY
使用C#。我有将完整目录复制到另一个目录的方法:
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;
}
}
我想知道将源目录成功复制到另一个目录后是否可以删除它。
答案 0 :(得分:2)
如果要保留.Net方法,则可以在finally语句中使用Directory.Delete。第二个参数指示删除子文件夹/文件。更多详细信息here
Directory.Delete(path,true);
答案 1 :(得分:0)
您可以使用robocopy
代替xcopy
robocopy from_folder to_folder files_to_copy /MOVE
xcopy
需要.bat
脚本才能具有与robocopy
的1行相同的功能
例如:
xcopy /D /V %1 %2
if errorlevel 0 (
del /Q %1
exit /B
)