Click to See Complete Forum and Search --> : Drive Selector


jmgreene
May 23rd, 1999, 03:27 PM
How can I have a box with the available drives and then when one is chosen have another box with all the directories in that drive?
Also does anyone know a recursive solution using FindNextFile to search subdirectories of a chosen directory.

Thanks.

Pallavi
May 24th, 1999, 03:53 AM
Hi,
U can use the following peice of code to fill in the list of current drives.
m_cDrive is a Combo Box here.

// Begin
DWORD dwDrive = GetLogicalDrives();
DWORD mask = 1;
char ch[5], cDrv[5], cddrv[5];
for (int drive = 1; drive <=26; drive ++) {
if (dwDrive & mask) {
sprintf( cddrv, "%c:\\", drive + 'A' - 1 );
UINT cdrom= GetDriveType(cddrv);
if ((cdrom != DRIVE_CDROM ) && (cdrom != DRIVE_REMOTE )){
sprintf( ch, "%c", drive + 'A' - 1 );
m_cDrive.AddString(ch) ;
}
}
mask = mask << 1;
}

drive = _getdrive();
sprintf( cDrv, "%c", drive + 'A' - 1 );
m_cDrive.SelectString(-1, cDrv) ;
// End

Here, the listing of CDROM drive and network drives are omitted. If U want to have those also in U'r listing, U can remove the check for that.

To get the directory listing, I think the following command might be helpful.
In lpPathSpec, I think U can specify the drive.

DlgDirList( LPTSTR lpPathSpec, int nIDListBox, int nIDStaticPath, UINT nFileType );

Have not tried using the above command myself.

Hope this will be helpful.

Pallavi

jmgreene
May 24th, 1999, 06:18 AM
The _getdrive() doesn't work though. Please advise. Thanks.

Pallavi
May 24th, 1999, 06:33 AM
Hi,
Well it did work for me!!!!
U can omit that part of the code (last three lines).
That was just for selecting and displaying the current drive in the list when the list comes up.
GetLogicalDrives() must work. Doesn't it?.

jmgreene
May 24th, 1999, 06:40 AM
I got the drive selector to work. How do I use the directory listing function? Thanks.

Pallavi
May 24th, 1999, 07:40 AM
U can use this function I guess to get the directory listing. I haven't used it myself, just referred the help and found out that it might be something U want.
The lpPathSpec contains the drive name eg. "c:\*.*", the next parameter is the id of the combo box where U want the list to be displayed ,the next parameter can be ignored I guess, U might put a zero, and the last param would be DDL_DIRECTORY in U'r case.

U can look up help and find out more about this function.
DlgDirListComboBox( LPTSTR lpPathSpec, int nIDComboBox, int nIDStaticPath, UINT nFileType );

Good Luck