CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Drive Selector

  1. #1
    Join Date
    May 1999
    Location
    Raleigh, NC
    Posts
    47

    Drive Selector

    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.


  2. #2
    Join Date
    May 1999
    Posts
    44

    Re: Drive Selector

    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


  3. #3
    Join Date
    May 1999
    Location
    Raleigh, NC
    Posts
    47

    Re: Drive Selector

    The _getdrive() doesn't work though. Please advise. Thanks.


  4. #4
    Join Date
    May 1999
    Posts
    44

    Re: Drive Selector

    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?.


  5. #5
    Join Date
    May 1999
    Location
    Raleigh, NC
    Posts
    47

    Re: Drive Selector

    I got the drive selector to work. How do I use the directory listing function? Thanks.


  6. #6
    Join Date
    May 1999
    Posts
    44

    Re: Drive Selector

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured