gpt4 book ai didi

c# - 使用 cmd shell 合并目录的内容

转载 作者:行者123 更新时间:2023-11-30 13:33:12 33 4
gpt4 key购买 nike

我想将一个目录中的所有文件合并为一个。但是我尝试了几个版本,但似乎都不起作用。我收到一条错误消息,指出找不到该文件。这是我正在尝试的:

        String outputFile = this.outputTxt.Text;
String inputFolder = this.inputTxt.Text;
String files = "";
String command;
foreach (String f in Directory.GetFiles(inputFolder))
{
files += f+"+";
}
files = files.Substring(0, files.Length - 1);
command = files + " " + outputFile;

Process.Start("copy",command);

我想获得的样本:复制a.txt+b.txt+c.txt+d.txt输出.txt

我得到的错误是:

System.dll 中发生类型为“System.ComponentModel.Win32Exception”的未处理异常

补充信息:系统找不到指定的文件

最佳答案

尝试启动 cmd 而不是“启动”进程。

Process.Start("cmd", "copy " + command);

“复制”是命令提示符中的一个命令,别名为...某物,而不是 Windows 知道如何运行的实际文件本身(在命令提示符之外)。

如果您不想在程序运行时在屏幕上弹出 shell 弹出的窗口,则可以使用 Process 类的一些属性。

关于c# - 使用 cmd shell 合并目录的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9177852/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com