It depends what framework/library you are using. You may be forced to open folder and iterate through its content, like
for( directory_iterator it(YourPath); it != directory_iterator(); ++it)
{
// increment variable here
}
in case of boost, or get the files count like
QDir.count() // returns the total count of files and directories in the directory
// use flags QDir::Filters with QDir::NoDotAndDotDot to exclude
// . and ..
in case of Qt.