Skip to main content
 首页 » 编程设计

c#之如何在CMD中使用SET和COPY

2024年02月20日8langtianya

在 C# Win Forms 中处理这个问题。

如何设置变量并在运行命令复制之后? 正如现在的代码一样,Process1.startInfo.Arguments = "/k SET 等等。"被“/k COPY 等覆盖”命令,那里没有执行。

    public void OutputBtn_Process_Click(object sender, EventArgs e) 
    { 
        foreach (FileInfo fi in listBox1.Items) 
        { 
            Process process1 = new Process(); 
            process1.StartInfo.Arguments ="/k Set filename ="+fi.Name; 
            process1.StartInfo.UseShellExecute = false; 
            process1.StartInfo.Arguments = "/k copy /b %filename% test.txt"; 
            //process1.StartInfo.LoadUserProfile = true; 
            process1.StartInfo.FileName = "cmd.exe"; 
            process1.StartInfo.WorkingDirectory = Path.GetDirectoryName(fi.FullName); 
            process1.Start(); 
        } 
    } 

请您参考如下方法:

回复:环境变量

ProcessStartInfo ( ProcessStartInfo.EnvironmentVariables) 中有一个集合可供您使用。

回复:复制文件。
使用 File.Copy .

File.Copy(src, destination);