This documentation is archived and is not being maintained.


Adds a list of filenames or drives to the list box of a combo box.

int Dir(
   UINT attr,
   LPCTSTR lpszWildCard 



Can be any combination of the enum values described in CFile::GetStatus or any combination of the following values:

  • DDL_READWRITE   File can be read from or written to.

  • DDL_READONLY   File can be read from but not written to.

  • DDL_HIDDEN   File is hidden and does not appear in a directory listing.

  • DDL_SYSTEM   File is a system file.

  • DDL_DIRECTORY   The name specified by lpszWildCard specifies a directory.

  • DDL_ARCHIVE   File has been archived.

  • DDL_DRIVES   Include all drives that match the name specified by lpszWildCard.

  • DDL_EXCLUSIVE   Exclusive flag. If the exclusive flag is set, only files of the specified type are listed. Otherwise, files of the specified type are listed in addition to "normal" files.


Points to a file-specification string. The string can contain wildcards (for example, *.*).

If the return value is greater than or equal to 0, it is the zero-based index of the last filename added to the list. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new strings.

This function is not supported by the Windows ComboBoxEx control. For more information on this control, see ComboBoxEx Controls in the Platform SDK.

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

// Add all the files and directories in the windows directory.
TCHAR lpszWinPath[MAX_PATH], lpszOldPath[MAX_PATH];
::GetWindowsDirectory(lpszWinPath, MAX_PATH);

// Make the windows directory the current directory.
::GetCurrentDirectory(MAX_PATH, lpszOldPath);

pmyComboBox->Dir(DDL_READWRITE|DDL_DIRECTORY, _T("*.*"));

// Reset the current directory to its previous path.