需要掌握 Windows 批处理语法
我在 Windows 上编译了一个 C++ 程序,我需要它来处理大量的数据文件。例如,这些文件被命名为“x0000y”至“x9999y”。
C++ 程序一次仅获取一个文件,创建每个文件的输出,保存在某处,然后终止。我不想对程序进行硬编码,因为我的数据集并不总是具有相同数量的文件 - 仅仅为此而不断重新编译程序并不酷。所以我正在寻找一种快速的方法来做到这一点:批处理。
麻烦来了:我在尝试使批处理语法正确且有效时遇到困难。那么有人可以向我展示以下批处理版本中的伪代码吗?:
for (int i = 0; i < lastFile; i++){
String filename;
/*
Because the files are named "x0000y", "x0034y", etc.
We need to put in all the extra 0s in the string if i is less than 1000.
*/
String numberedString = convertNumToFourDigit(i);
filename = "myFileName" + numberedString + "Footer";
/*
execute the program with the respective filename.
*/
execute("MyProgram.exe " + filename);
}
I have compiled a C++ program on Windows, and I need it to process a huge number of my data files. The files are named, for instance, "x0000y" to "x9999y".
The C++ program only takes one file at a time, create the output of each respective file, save somewhere, and terminate. I do not want to hard code the program, as my data set does not always have the same number of files - and keep recompiling the program just for this is not cool. So I am looking for a quick way of doing this: batch processing.
Here comes the trouble: I am having trouble trying to get the batch syntax correct and valid. So could somebody show me the following pseudocode in batch processing version?:
for (int i = 0; i < lastFile; i++){
String filename;
/*
Because the files are named "x0000y", "x0034y", etc.
We need to put in all the extra 0s in the string if i is less than 1000.
*/
String numberedString = convertNumToFourDigit(i);
filename = "myFileName" + numberedString + "Footer";
/*
execute the program with the respective filename.
*/
execute("MyProgram.exe " + filename);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是 .bat 文件中所需的全部内容,以便针对当前目录中的所有文件运行程序。
如果数据文件位于具有扩展名的子目录中,则这里有一个示例。
如果您只需要 x0000y 形式的文件,那么这就可以了。
它们将以文件系统提供名称的任何顺序处理数据文件。
This is all you'll need in your .bat file to run your program against all of the files in the current directory.
If the data files are in a subdirectory with an extension, here's an example.
If you only want files in the form of x0000y, then this will do the trick.
These will process the data files in whatever order the filesystem provides their names.