Select Folder dialog


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

The SelectFolder.zip file contains the SelectFolder.exe whose output is shown in the above picture. The "Options of Select Folder dialog" dialog shown in the above picture, shows the capabilities of the CSelectFolder class

Environment: Visual C++5, Windows NT 4 (SP3)

This Select Folder dialog was originally done by Mihai Filimon. I have added the following features -

  1. Added a edit control where the user can type in the path
  2. If the path typed in the edit ctrl does not exist then the user will be propmted as to whether he/she wants the path to be created
  3. Setting the flag bShowFilesInDir to TRUE will result in all the files in the current folder to be displayed in the dialog
  4. If you don't want to display all the files then you can use the file filter to display the file types you want to display

Some more additional features

  1. Calling API SetTitle with the desired title will set the Title of the dialog. This API has to be invoked before DoModal is called
  2. User can pass the Initial Folder to be displayed in the constructor of CSelectFolder


CSelectFolderDialog(BOOL bShowFilesInDir = FALSE, LPCSTR lpcstrInitialDir = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL);

Usage Examples

  • CSelectFolderDialog oSelectFolderDialog(FALSE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL, NULL);
  • CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,NULL, NULL);
  • CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Microsoft Word Documents (*.doc)|*.doc|Microsoft Excel Worksheets (*.xls)|*.xls|", NULL);
  • CSelectFolderDialog oSelectFolderDialog(TRUE, "c:\\my documents",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"HTML Files (*.html, *.htm)|*.html;*.htm||", NULL);

Heres a complete example on how i got the select folder dialog shown in the above picture

CSelectFolderDialog oSelectFolderDialog(TRUE, "C:\WINNT", OFN_HIDEREADONLY | 
 OFN_OVERWRITEPROMPT, "Microsoft Word Documents (*.doc)|*.doc|Microsoft Excel
 Worksheets (*.xls)|*.xls|", this);

if (oSelectFolderDialog.DoModal() == IDOK)


Download demo project - 27 Kb


  • CSelectFolderDialog not working in VS2010

    Posted by Rinky on 01/22/2014 12:18pm

    Please post the classes if they are updated for the selected folder dialog.

  • Disable displayed files

    Posted by pmurgai on 12/30/2005 11:52pm

    My requirement is that the user should be able to select only folders and not the files. Is there a way to show files as disabled (grayed out) in the listbox so that the only option is to select folders ?

  • Application crashed in VC.NET

    Posted by Legacy on 06/09/2003 07:00am

    Originally posted by: Dennis

    After clicking on the 'Show Dialog' button, the application crashes on the line


    It looks like the pFD->GetDlgItem(edt1) return a NULL pointer.

    This does not happen in VC6.0. Any idea on how to resolve this?


  • when selecting c:\\winnt\fonts dir and exit dlg, it will result in error!

    Posted by Legacy on 08/02/2002 07:00am

    Originally posted by: liaohuanlin

    as title

  • Path always created?

    Posted by Legacy on 07/11/2002 07:00am

    Originally posted by: Kevin Jackman

    When the "This path does not exist, do you want to create it?" dialog appears, selecting 'NO' creates it anyway.

    Adding 'else return NULL' seems to fix it

    if(AfxMessageBox(cstrPath + _T("\n") + _T("\n") +_T("This path does not exist. Do you want to create it?"),
    else return NULL; // this line has been added

    I have inherited this code from a colleague,so I apologise if this comment is inaccurate.

  • There have some leak of User objects

    Posted by Legacy on 06/17/2002 07:00am

    Originally posted by: David

    show it , user objects will add and donn't release.
    how to resolve it?

  • MakeSureDirectoryPathExists and unicode

    Posted by Legacy on 02/06/2001 08:00am

    Originally posted by: Alan

    Does anyone know if a unicode version of this call exists ?

  • Context sensitive help

    Posted by Legacy on 10/30/2000 08:00am

    Originally posted by: Rick Bogard

    I noticed that when you use the "?" button to get help, that the "Select" button displays the help for an "Open" button. Is there any way to change this behavior?

  • Can't force folder to exist

    Posted by Legacy on 08/16/2000 07:00am

    Originally posted by: Carnegie

    Is it possible to force the user to select an existing directory?
    I've tried using both OFN_FILEMUSTEXIST and OFN_PATHMUSTEXIST, but neither changes the behaviour of the dialog box if a nonexistant path is entered in the text box - the 'Path does not exist, do you wish to create it' message is still displayed.

    I want the user to be able to type the path as well as select it with the mouse, so I can't just set the edit box to Read Only.

    Still a great piece of code though.

  • Can't select folders from the network

    Posted by Legacy on 11/02/1999 08:00am

    Originally posted by: Shirly Armin


    I use this class and it's very cool , BUTTT -->
    When trying to select a folder from the network :
    for example : "\\websql\student\" ,
    an Error Message Box ""Invalid Folder" is displayed.
    I'v found your remark in the source :

    //If the user has entered something like
    //this is invalid but _access returns valid if this string is passed to
    //it. So before giving it to _access validate it.

    So, This is A Problem!!!!!!!

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date