Using DlgDirList function

Posted on 2000-02-29
Last Modified: 2012-08-14
I am trying to use the DlgDirList function which fills the specified list box
with the names of all files matching the specified path or filename. How do you use it I have tried and I can not get it to work.  I want the list box to list the contents of a specified directory, is this possible.

Question by:Richard_Eustace
  • 3
  • 3

Accepted Solution

Wyn earned 100 total points
Comment Utility
For Example:


This would list all .exe files to the ListBox named LISTEXE with the static path being PATH.  It will also list the directories and drives.

Expert Comment

Comment Utility
FYI ,here is description of that API:

The DlgDirList function fills the specified list box with the names of all files matching the specified path or filename.

int DlgDirList( HWND hDlg,
 // handle to dialog box with list box
LPTSTR lpPathSpec,
 // pointer to path or filename string
int nIDListBox,
 // identifier of list box
int nIDStaticPath,
 // identifier of static control
UINT uFileType
 // file attributes to display


Identifies the dialog box that contains the list box.


Points to a null-terminated string that contains the path or filename. DlgDirList modifies this string, which should be long enough to contain the modifications. For more information about this parameter, see the Remarks section.


Specifies the identifier of a list box. If this parameter is zero, DlgDirList assumes that no list box exists and does not attempt to fill one.


Specifies the identifier of the static control used for displaying the current drive and directory. If this parameter is zero, DlgDirList assumes that no such control is present.


Specifies attributes of the filenames to be displayed. This parameter must be one or more of the following values: Value
 Includes archived files.
 Includes subdirectories. Subdirectory names are enclosed in square brackets ([ ]).
 Includes drives. Drives are listed in the form [-x-], where x is the drive letter.
 Includes only files with the specified attributes. By default, read-write files are listed even if DDL_READWRITE is not specified.
 Includes hidden files.
 Includes read-only files.
 Includes read-write files with no additional attributes.
 Includes system files.
 Posts messages to the application¡¯s message queue. By default, DlgDirList sends messages directly to the dialog box procedure.

Return Values
If a listing is made ¾ even an empty listing ¾ the return value is nonzero. If the input string does not contain a valid search path, the return value is zero.

If you specify a zero-length string for the lpPathSpec parameter or if you specify only a directory name with no filename, the string will be changed to *.*

The lpPathSpec parameter has the following form:

[drive:] [[\u]directory[\idirectory]\u] [filename]

In this example, drive is a drive letter, directory is a valid directory name, and filename is a valid filename that must contain at least one wildcard (? or *).

If lpPathSpec includes a drive or directory name, or both, the current drive and directory are changed to the specified drive and directory before the list box is filled. The static control identified by the nIDStaticPath parameter is also updated with the new drive or directory name, or both.

After the list box is filled, DlgDirList updates lpPathSpec by removing the drive or directory portion, or both, of the path and filename.

DlgDirList sends the LB_RESETCONTENT and LB_DIR messages to the list box.  
Free to ask.

Expert Comment

Comment Utility
Btw: the *.exe is simply an example.You can specify your path and filename.Plz consult the description above.
If problem exists,A-S-K
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!


Expert Comment

Comment Utility
This first parm hWnd isn't needed when using MFC...I haven't been able to get the function to work using the wrapper in MFC...anybody have samle code where a listbox in a dialog can be filled with Drives/directories/files on NT4.0?

Expert Comment

Comment Utility
I forgot to specify I'm using MFC 6.0 using VC++ 6.0

Expert Comment

Comment Utility
I got it to work using's the code:

char szPath [MAX_PATH] = {"c:\\"} // sets a string array of maximum path length to starting path

int nResult = DlgDirListComboBox (szPath,IDC_COMBOBOX1,IDC_STATICPATH,DDL_DRIVES | DDL_DIRECTORY); // loads combo box with drives and directories

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now