The idea is simple. Folders or directories do not have any .extensions. So you could read all files into an array and filter out all the ones with dot extensions.
However, a more reliable way would be to use this example, taken from adrianxw's site.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE hFind;
WIN32_FIND_DATA FindData;
cout << "A very basic FindFirst/Next demo.\n" << endl;
// Find the first file
hFind = FindFirstFile("C:\\*.*", &FindData);
while (FindNextFile(hFind, &FindData))
{
//cout << FindData.cFileName;
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
cout << FindData.cFileName;
cout << " File is a directory!";
cout << endl;
}
}
// Close the file handle
FindClose(hFind);
cin.get();
return 0;
}
Just as a side note you can easily make directory's and remove as well using this example...
Code:
/* MAKEDIR.C */
#include <direct.h> //need this baby
#include <stdlib.h>
#include <stdio.h>
int main( )
{
_mkdir( "c:\\treenef" );
printf( "Directory '\\treenef' was successfully created\n" );
//To remove the directory uncomment below
//if( _rmdir( "c:\\treenef" ) == 0 )
//printf( "Directory '\\treenef' was successfully removed\n" );
system("pause");
return 0;
}