简体   繁体   中英

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). 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?

It seems unlikely that a library exists for such a specific task. You could use boost::filesystem to check for existence of directories. The size of the code to implement the needed functionality shouldn't exceed 20 lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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