I have a directory full of files named
foo-1.ocf
foo-2.ocf
bar-1.ocf
bar-2.ocf
file-1.ocf
file-2.ocf
I want to iterate over each pair of files, if bot files exist (-1.ocf
and -2.ocf
).
What is a good approach to do this in boost?
Asked
Active
Viewed 65 times
0

tzippy
- 6,458
- 30
- 82
- 151
-
What's supposed to happen if there's only one file of the pair? – jrok Apr 17 '15 at 09:24
-
@jrok you do not include it in your iteration :) – Selçuk Cihan Apr 17 '15 at 09:25
-
@SelçukCihan Or maybe stop the iteration completely? I'd rather have OP clarify this. – jrok Apr 17 '15 at 09:26
-
If a file occurs, for which there is no "partner", just drop that file. – tzippy Apr 17 '15 at 09:27
1 Answers
1
Obtain a sorted list of files, here's a tutorial.
Run through that list remembering (a) if the previous file had suffix
-1
and (b) the prefix of the previous file.So if current file has the same prefix as the previous, and the previous file had suffix
-1
, and current file has suffix-2
- then you got another pair of files.

Anton Savin
- 40,838
- 8
- 54
- 90