【发布时间】:2011-07-18 07:22:15
【问题描述】:
我正在尝试将文件复制到映射驱动器上的网络文件夹。我在我的命令行中测试了 COPY,它有效,所以我想我会尝试在 C# 中自动化这个过程。
ProcessStartInfo PInfo;
Process P;
PInfo = new ProcessStartInfo("COPY \"" + "c:\\test\\test.txt" + "\" \"" + "w:\\test\\what.txt" + "\"", @"/Z");
PInfo.CreateNoWindow = false; //nowindow
PInfo.UseShellExecute = true; //use shell
P = Process.Start(PInfo);
P.WaitForExit(5000); //give it some time to finish
P.Close();
引发异常:System.ComponentModel.Win32Exception (0x80004005):系统找不到指定的文件
我错过了什么?我是否必须在命令参数中添加任何其他内容?
我尝试过 File.Copy,但它似乎不起作用 (File.Exists("<mappeddriveletter>:\\folder\\file.txt");) 出现错误。
【问题讨论】:
-
File.Exists("\\server\file.txt")当然,那将返回 false。您需要转义反斜杠,或使用@-string:File.Exists(@"\\server\file.txt")
标签: c# networking command-line batch-file copy