majestik666@gmail.com wrote:
Quote:
[..]
Well I guess my c++ question is about
how do you list a folder, and while doing that
collapsing the filenames that are in the form prefix.%d.suffix
into "groups" like prefix.[first-last].suffix
it's not image related really, just about how to work out
the strings to collapes into one.
|
Ah... OK. Folders aside, files aside, your question is what you
should do to form "blah.[N-M].blah" if you have a bunch of strings
all containing "blah.<N>.blah", "blah.<N+1>.blah", etc., until the
"blah.<M>.blah" where N and M are two numbers. Right?
This is not a C++ language question. It's an algorithm question.
You need an algorithm for string processing. I would probably
suggest something like
// find the beginning of the sequence
int N;
for (N = 0; N < INT_MAX; ++N) {
std::ostringstream os;
os << "prefix." << N << ".suffix";
std::string filename(os.str());
if (/* exists the file with pattern 'filename' */)
break;
}
// now N is your start
int M;
for (int M = N; M<INT_MAX; ++M) {
std::ostringstream os;
os << "prefix." << M << ".suffix";
std::string filenam(os.str());
if (/* does NOT exist file with pattern 'filename' */)
break;
}
if (--M N) { // got the sequence!
std::ostringstream os;
os << "prefix.[" << N << '-' << M << "].suffix";
return os.str(); // here you go
}
else { // it's a single file, maybe.
...
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask