You'll need to use something specific to your operating system or an external library. Nothing in STD C++ will do this.
I recommend the boost::filesystem library as it can be used in any operating system.
Once installed, you can do that with this function:
1 2 3 4 5 6 7 8 9 10 11 12 13
int count_files(std::string directory, std::string ext)
namespace fs = boost::filesystem;
int Nb_ext = 0;
fs::directory_iterator end_iter; // Default constructor for an iterator is the end iterator
for (fs::directory_iterator iter(Path); iter != end_iter; ++iter)
if (iter->path().extension() == ext)
You wite a c++ program, maybe LookupCount.exe
The Program should look at the second last entry of a temporary file, where it will find the count. This count the program should return (or print it also).
Then you write the following lines in a batch file (.cmd or .bat)
dir file.txt > temp.txt
LookupCount .exe temp.txt
echo Count: %errorlevel%