Folder listing

This is a discussion on Folder listing within the Windows Programming forums, part of the Platform Specific Boards category; Hi using MFC how could I go about getting the listing of folder on a certain drive, say I get ...

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Folder listing

    Hi using MFC how could I go about getting the listing of folder on a certain drive, say I get the user to choose the drive from a drop down box, how can i then look at that drives contents, but specifically folders.

    Thanks.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Thanks, that will probably help, it's gonna take me a while to understand it properly though.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Another possibility is to use a CListBox control and fill it up with file/directory names with the DlgDirList api. Something like:
    Code:
    //get length of path to windows dir
    int len=GetEnvironmentVariable("windir",0,0);
    if (len)
      {
      char *path=new char[len+1];
          
      GetEnvironmentVariable("windir",path,len);
      //fill listbox with file/directory names
      int ret=::DlgDirList(*this,path,IDC_LIST1, IDC_STATIC_DIR,
                           DDL_DIRECTORY|DDL_EXCLUSIVE|DDL_SYSTEM);
          
      delete[] path;
      }
    else
      {
      //error
      }
    where this is the CWnd parent object of the CListBox control, IDC_LIST1 is the listbox id and IDC_STATIC_DIR the id of a 'buddy' static control. You might have to fiddle around a bit to get a format to suit (eg. convert short to long filenames).

    I don't use mfc much so there may be a more mfc friendly way of implementing this approach that others may be able to suggest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  3. Not able to access directory of home folder
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 02-06-2008, 01:45 AM
  4. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 08:18 AM
  5. Hiding a folder
    By nextstep in forum Windows Programming
    Replies: 16
    Last Post: 03-20-2005, 02:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21