以下代码自言自语。当我尝试将本地文件夹Xcopy Xcopy到网络藏品时,路径都弄乱了,CMD无法正确地插入后挡板。欢迎任何建议,已经尝试了我在网络上发现的所有内容(几乎被困了2个小时(:
string command = "xcopy /s " + @"C:UsersMeDesktopTempExtractMyApp*.* " + @"\TestShareSharedFolderApplications /Y /I";
Process Processo = new Process();
ProcessStartInfo Xcopy = new ProcessStartInfo("cmd.exe");
Xcopy.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Xcopy.Arguments = command;
Processo = Process.Start(Xcopy);
Processo.WaitForExit();
这里的问题是"参数"不能解码为" ",所以我的路径就像:
C:\Users\Me\Desktop\TempExtract\MyApp\*.*
和cmd不能插入双反斜线:( help!
我认为问题在于您设置ProcessStartInfo
的方式。因此command
应该是:
string command = @"C:UsersMeDesktopTempExtractMyApp*.* " + @"\TestShareSharedFolderApplications /Y /I";
并添加
Xcopy.FileName = "xcopy";
这对我有用:
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
var command = @"C:UsersMeDesktopTempExtractMyApp*.* " + @"\TestShareSharedFolderApplications /Y /I";
var Processo = new Process();
var Xcopy = new ProcessStartInfo("cmd.exe")
{
Arguments = command,
FileName = "xcopy",
UseShellExecute = false
};
Processo = Process.Start(Xcopy);
Processo.WaitForExit();
}
}
尝试在开始或命令字符串中添加 /c
(因为cmd.exe通过/c参数启动以下命令,请检查cmd.exe的帮助(。如果那没有问题,请在路径周围添加"
。