Sorry if the post is a little bit long. It's not exactly a problem per se, just interested to know how other programmers would have approached this. . .
Essentially, I'm implementing an image processing program. The images are stored in a folder and are numbered for example: Image000.JPG, Image001.JPG, Image002.JPG... Imagexxx.JPG. The names of the images have a constant text in this case "Image" and an extension, in this case "JPG". These files are to be read in order i.e Image000.JPG before Image001.JPG.
1. The first solution simply provides a config file where the user inputs the "constant text"(Image) and the number of images N.This config entry needs to be modified each time the names of images change. Probably small trouble.
The program accesses each image by using a counter:
for(int i = 0; i < N; i++)
image.open("Image" + i + ".JPG")
*note the above code is just an illustration and will not compile!
2. The second simply takes the name of the folder where the images are stored and accesses the files using some system calls.
Since, the files are usually retrieved unsorted the program needs to do the sorting itself. It automatically figures out the "common text" and the likely file extensions. It works quite well and needs to run only once at the start of the program.
It's attractive because one could do OOP stuffs like:
while(!directory.end())
{
string name = directory.next();
image.open(name);
}
However, it seems to be complicating what is a simple problem? There is also the small overhead of creating a new class with its associated functions.
Which would you program?