简体   繁体   English

是否有一个库可以在C ++中创建一组具有相同名称和索引的目录?

[英]Is there a library to create a set of directories with the same name and an index in C++?

I am writing a program that will generate many output files each time I run it. 我正在编写一个程序,每次运行它时都会生成许多输出文件。 I added the option to specify an output directory so that I don't clutter up my source directory. 我添加了指定输出目录的选项,这样我就不会弄乱我的源目录。 However, I don't want to have to change the name every time I run it (I'm lazy in that way), since I am still developing it, and I am iterating fast. 但是,我不想每次运行它时都要更改名称(我这样懒,因为我还在开发它,而且我正在快速迭代)。

The elegant solution I had in mind was that if I specify the output foo , and foo already exists, my program should create foo.0 , then foo.1 and so on, ad nauseum (or until I run out of disk space). 我想到的优雅解决方案是,如果我指定输出foo ,并且foo已经存在,我的程序应该创建foo.0 ,然后foo.1等等,ad nauseum(或直到我用完磁盘空间)。 I've seen this done by many tools I've used. 我已经通过我使用的许多工具看到了这一点。

I can pretty easily write some sort of loop that checks for the existence of each indexed name, and increments the index until it finds an unused one. 我可以很容易地编写某种循环来检查每个索引名称的存在,并递增索引,直到它找到一个未使用的名称。 However, I've seen this done by so many tools that it seems logical that there's some sort of library that does this. 但是,我已经通过这么多工具看到了这一点,似乎合乎逻辑的是有某种类型的库可以做到这一点。

My question is: Is there any C++ library that I can use that will create a directory with a given name + the next free index? 我的问题是:我是否可以使用任何C ++库创建一个具有给定名称+下一个免费索引的目录?

It seems unlikely that a library exists for such a specific task. 对于这样一个特定的任务,似乎不太可能存在库。 You could use boost::filesystem to check for existence of directories. 您可以使用boost::filesystem来检查目录是否存在。 The size of the code to implement the needed functionality shouldn't exceed 20 lines. 实现所需功能的代码大小不应超过20行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM