#include "stdafx.h"
#include "Windows.h"
#include <vector>
#include <string>
#include "iostream"
using namespace Std;
int GetSubfolders (string& folder, vector<string>& subfolders)
{
Subfolders.clear ();
Win32_find_dataa Filefinddata;
String NAMEWC = folder + "//*";
HANDLE hfind =:: Findfirstfilea (Namewc.c_str (), &filefinddata);
if (hfind = = INVALID_HANDLE_VALUE)
{
cout<< "Folder path error ..." <<endl;
System ("pause");
return 0;
}
Do
{
if (filefinddata.cfilename[0] = = '. ')
{
Continue Filter the '. ' and '. ' In the path
}
if (filefinddata.dwfileattributes = = file_attribute_directory)
{
Subfolders.push_back (folder+ "//" +filefinddata.cfilename);
}
}while (:: Findnextfilea (Hfind, &filefinddata));
FindClose (hfind);
return (int) subfolders.size ();
}
int main (int argc, char* argv[])
{
String folder = "E:";
Vector<string> SubDir;
int count = getsubfolders (folder, subdir);
cout<< "Count =" <<count<<endl;
for (int i=0; i<count; i++)
{
Cout<<subdir[i].c_str () <<endl;
}
System ("pause");
return 0;
}
After running, traverse all the file directories in the E drive and print all directory names
Traverse all subfolders under the specified folder in Windows