Have you listed
all your requirements?
Vector vs list isn't much of a choice when there are many others to choose from (not including anything you can
custom design)
Containers library - cppreference.com
Do you intend to sort the list after you've read the files from the file system?
Don't assume that any order that comes from the file system is compatible with string comparison necessary for say a binary search.
How is the user supposed to 'know' an index number for a file?
Does your UI list all the files with a handy index number next to it?
Storing the whole path for every file is a massive overhead if you have lots of files in deep directories. I figure your 10M files aren't all in the root directory.
Vectors typically waste 25% of the allocated space.
Code:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> a;
vector<int>::size_type s = a.capacity();
for ( int i = 0 ; i < 10000000 ; i++ ) {
a.push_back(i);
vector<int>::size_type q = a.capacity();
if ( s != q ) {
cout << "At index << " << i <<
", capacity increased from " << s <<
" to " << q << endl;
s = q;
}
}
}
$ g++ foo.cpp
$ ./a.out
At index << 0, capacity increased from 0 to 1
At index << 1, capacity increased from 1 to 2
At index << 2, capacity increased from 2 to 4
At index << 4, capacity increased from 4 to 8
At index << 8, capacity increased from 8 to 16
At index << 16, capacity increased from 16 to 32
At index << 32, capacity increased from 32 to 64
At index << 64, capacity increased from 64 to 128
At index << 128, capacity increased from 128 to 256
At index << 256, capacity increased from 256 to 512
At index << 512, capacity increased from 512 to 1024
At index << 1024, capacity increased from 1024 to 2048
At index << 2048, capacity increased from 2048 to 4096
At index << 4096, capacity increased from 4096 to 8192
At index << 8192, capacity increased from 8192 to 16384
At index << 16384, capacity increased from 16384 to 32768
At index << 32768, capacity increased from 32768 to 65536
At index << 65536, capacity increased from 65536 to 131072
At index << 131072, capacity increased from 131072 to 262144
At index << 262144, capacity increased from 262144 to 524288
At index << 524288, capacity increased from 524288 to 1048576
At index << 1048576, capacity increased from 1048576 to 2097152
At index << 2097152, capacity increased from 2097152 to 4194304
At index << 4194304, capacity increased from 4194304 to 8388608
At index << 8388608, capacity increased from 8388608 to 16777216
std::vector - cppreference.com
In order to achieve this amortization, the usual strategy is to double the amount of space each time.
Also, vectors are constrained to be in contiguous memory. This is usually fairly low cost if all you're doing is extending a single vector with a POD type. But filling each vector entry with dynamic objects like strings (which cause further allocations) is likely to result in your entire vector being moved every time it's extended.
Or call .reserve() with a big number to start with.
But vector will give you the O(1) index capability and O(Log(n)) search capability (after you sort it). Again, we're back to your requirements.
Walking the directory tree is in the FAQ.
FAQ > Accessing a directory and all the files within it - Cprogramming.com