List of files in a directory?

Started by
0 comments, last by J-Baby 20 years, 4 months ago
Hi all, Is there a function in Visual C++ (6.0) that will return the list of files in a directory? Thank you, John
Advertisement
You need to look up three specific Win32 functions: FindFirstFile, FindNextFile and FileClose. FindFirstFile takes the directory name and a WIN32_FIND_DATA structure, and returns a file handle to the directory. You can use a do while loop, with FindNextFile as the condition, to loop through all the directories and files in the directory, and use the contents of the WIN32_FIND_DATA structure each time to determine if what''s found is a directory or a file, it''s name, creation date, and other details. Simply call FileClose with the handle to finish reading that directory.

The argument you specify to FindFirstFile also specifies the file type to search for, eg. "c:\\mydir\\*.*", or "c:\\mydir\\*.txt". If you need any more info, drop a post here...

Insert [CENSORED] here.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

This topic is closed to new replies.

Advertisement