【发布时间】:2011-07-23 05:02:53
【问题描述】:
我有一大堆纯文本文件,命名如下:file1.txt、file2.txt、...、file14.txt、... 我想将它们按正确顺序连接到一个 .txt 文件。 我应该如何以编程方式执行此操作? 在命令窗口中运行的批处理文件? 还是编写一个 Windows 控制台应用程序?
无论如何,我可以得到代码吗?谢谢。
更多信息:
大量文件。每次我做这个报告时都会有一百个或更多。
dir 不会以正确的顺序给出文件:例如 file10.txt 出现在 file2.txt 之前,这就是我强调的原因。从 1 到 n 连接到文件名前缀的 for i 似乎是最好的。但我不知道如何在批处理模式下或从 Windows 程序执行命令。
我倾向于做一个 Windows 控制台应用程序。这样的事情会奏效吗?
class Program
{
static void Main(string[] args)
{
string strCmdLine;
System.Diagnostics.Process process1;
process1 = new System.Diagnostics.Process();
Int16 n = Convert.ToInt16(args[1]);
int i;
for (i = 1; i < n; i++)
{
strCmdLine = "/C copy more work here " + args[0] + i.ToString();
System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
process1.Close();
}
}
}
【问题讨论】:
-
您有大量的小文件吗?少量大文件?两者都有一点?
-
-1 表示“我能拿到代码吗?”
-
这是一次性的吗?如果是这样,只需
copy file1.txt+file2.txt+file3.txt+and.so.on.txt destination.txt -
这里似乎有一个隐藏的挑战:如果文件按照他所说的那样命名,那么按照正确的顺序排列它们需要手动排序(正如@Michael Burr 建议的那样)或
StrCmpLogicalW(这是资源管理器的排序方式),因为如果数字
标签: .net windows command-line windows-console