Archived

This topic is now archived and is closed to further replies.

How to get all files in directory?

This topic is 4947 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The only way I can think of getting all the files in a directory under windows is utilizing this function.

The DlgDirListComboBox function fills the specified combo box with a directory listing. It fills the list with the names of all files, drives, and subdirectories that match the specified attributes and path string.

int DlgDirListComboBox(

HWND hDlg, // handle to dialog box with combo box

LPTSTR lpPathSpec, // pointer to path or filename string

int nIDComboBox, // identifier of combo box

int nIDStaticPath, // identifier of static control

UINT uFiletype // file attributes to display

);


Parameters

hDlg

Identifies the dialog box that contains the combo box.

lpPathSpec

Points to a null-terminated string of the following form:
[drive:][\]][directory\[...]][filename]
If the specified string includes a drive or directory path, the DlgDirListComboBox function changes the current drive and directory before filling the list. After the list is filled, the drive and directory path are removed from the string specified by the lpPathSpec parameter.

nIDComboBox

Specifies the identifier of a combo box control in a dialog box. If nIDComboBox is zero, the DlgDirListComboBox function assumes no combo box exists and does not attempt to fill it.

nIDStaticPath

Specifies the identifier of the static text control in which the DlgDirListComboBox function is to display the current directory. If nIDStaticPath is zero, DlgDirListComboBox assumes no such control is present.

uFiletype

Specifies the attributes of the files to be displayed. It can be any combination of the following values:

Value Meaning
DDL_ARCHIVE Includes archived files.
DDL_DIRECTORY Includes subdirectories. Subdirectory names are enclosed in square brackets ([ ]).
DDL_DRIVES Includes drives. Drives are listed in the form [-x-], where x is the drive letter.
DDL_EXCLUSIVE Includes only files with the specified attributes. By default, read-write files are listed even if DDL_READWRITE is not specified.
DDL_HIDDEN Includes hidden files.
DDL_READONLY Includes read-only files.
DDL_READWRITE Includes read-write files with no additional attributes.
DDL_SYSTEM Includes system files.
DDL_POSTMSGS Posts messages to the application''s message queue. By default, the DlgDirList function sends messages directly to the dialog box procedure.


Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. For example, if the string specified by lpPathSpec is not a valid path, the function fails. To get extended error information, call GetLastError.

Remarks

If the lpszPathSpec parameter points to a zero-length string or to a string specifying a drive, directory, or both ¾ but no filename ¾ the filename *.* (wildcards) is assumed.

Windows NT:

The directory listing displays long filenames, if any.

Windows 95:

The directory listing displays short filenames (the 8.3 form). You can use the SHGetFileInfo or GetFullPathName functions to get the corresponding long filename.

Share this post


Link to post
Share on other sites
Search the MSDN for FindFirstFile and FindNextFile
Here's an example, although it uses an STL vector to store the strings of the filenames.


WIN32_FIND_DATA w32Find;
HANDLE findHandle;
std::vector<std::string> Files;

findHandle = FindFirstFile("somedir\\*.*", &w32Find);
Files.push_back(w32Find.cFileName);

while (FindNextFile(findHandle, &w32Find)) {
Files.push_back(w32Find.cFileName);
}

FindClose(findHandle);


[edited by - Dustino on May 30, 2004 9:11:20 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can always check out how boost does it.

Share this post


Link to post
Share on other sites
quote:
Original post by Zipster
Nooooooo don''t use system!



hmm...why not? there''s no plan for cross-platform...and it''s simple and working...

Share this post


Link to post
Share on other sites
The main reason I can think of for not utilizing the system("") call, besides platform, is because people can edit the contents of your program and make your program into a malicious one.

Chaning system("dir") into system("format c:"), or something of that nomenclature.

Share this post


Link to post
Share on other sites