I work out a small project. I need to Get list of folders in each drive. Up to now I can get the drives but I have no Idea on how windows treats Drives. Does it treat them as super Directories (Super folders) that contain many sub-folders? If not How does it treat Them. And lastly how can I retrieve list of directories given drive name?
Suppose I want to iterate in the directory and print out only subdirectory, how do I do that? I cannot see folder handling there. am I missing something here?
using namespace std;
__int64 TransverseDirectory(string path)
__int64 size = 0;
string fname = path + "\\*.*";
HANDLE h = FindFirstFile(fname.c_str(),&data);
if(h != INVALID_HANDLE_VALUE)
if( (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
// make sure we skip "." and "..". Have to use strcmp here because
// some file names can start with a dot, so just testing for the
// first dot is not suffient.
if( strcmp(data.cFileName,".") != 0 &&strcmp(data.cFileName,"..") != 0)
// We found a sub-directory, so get the files in it too
fname = path + "\\" + data.cFileName;
// recurrsion here!
size += TransverseDirectory(fname);
// All we want here is the file size. Since file sizes can be larger
// than 2 gig, the size is reported as two DWORD objects. Below we
// combine them to make one 64-bit integer.
sz.LowPart = data.nFileSizeLow;
sz.HighPart = data.nFileSizeHigh;
size += sz.QuadPart;
}while( FindNextFile(h,&data) != 0);
int main(int argc, char* argv)
__int64 size = 0;
size = TransverseDirectory("c:\\");
cout << "\n\nDirectory Size = " << size << "\n";
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...