在win form工程中怎麽樣調用xcopy系統命令

sfanpu 2005-03-15 10:07:40
我想要實現文件夾的拷貝功能但是不知道怎麽樣調用xcopy命令,請大家幫忙。
...全文
141 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjaifly 2005-03-15
  • 打赏
  • 举报
回复
xcopy 的方法你可以看windows自己的帮助都有写!
程序 你用第2位兄弟的就可以
chagel 2005-03-15
  • 打赏
  • 举报
回复
private string RunCommand(string cmd)
{
string res = String.Empty;
string error = String.Empty;
Process p = new Process();
StreamWriter sw;
StreamReader sr;
//StreamReader err;

ProcessStartInfo psI = new ProcessStartInfo("cmd");
psI.UseShellExecute = false;
psI.RedirectStandardInput = true;
psI.RedirectStandardOutput = true;
psI.RedirectStandardError = true;
psI.CreateNoWindow = true;
p.StartInfo = psI;

try
{
p.Start();
sw = p.StandardInput;
sr = p.StandardOutput;
//err = p.StandardError;

sw.AutoFlush = true;
sw.WriteLine(cmd);
sw.Close();
//error = err.ReadToEnd();
res = sr.ReadToEnd();

//err.Close();
sr.Close();
p.Close();
}
catch(Exception e)
{
MessageBox.Show("Error when run command: " + cmd + "\n" + e.Message + "\n");
return "";
}

if(error.Length != 0)
{
MessageBox.Show("Error when run command: " + cmd + "\n" + error + "\n");
return "";
}
return res;
}
t0h 2005-03-15
  • 打赏
  • 举报
回复
strCmd=" /c xcopy /E /C /Y \""+txtServerAddress.Text.Trim()+"\" " + " \""+@"C:\test\" +"\" ";
System.Diagnostics.Process.Start("cmd.exe ",strCmd);

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧