|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading a Directory in Windows?
Hello,
I am familiar with opendir, readdir, ect. that linux uses. However, I would like to know what functions and headers to use to read a directory in a windows enviroment. I have tried searching the msdn, but I have not had any luck yet. Eclipce
__________________
Baptism By The Scriptures | Fifty Objections to Baptism Answered | HTML Bible | God's Salvation Plan Lifetime Residual Income |
|
#2
|
|||
|
|||
|
I think winbase.h defines these functions.
Code:
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile("c:\mydir\*.*", &fd);
if (hFind != INVALID_HANDLE_VALUE) // make sure valid
{
do
{
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) // don't care about directories
MyFunction(fd.cFileName);
} while (::FindNextFile(hFind, &fd)); // enumerates contents
::FindClose(hFind);
}
I've only used them in MFC, so the framework may have automatically imported other necessary libraries, etc. Either way, if you look the MSDN with the above functions, I'm sure you'll figure it out. If you need to enumerate through sub-directories too, check the SetCurrentDirectory() function too. |
|
#3
|
|||
|
|||
|
Thanks a bunch!
![]() Eclipce |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Reading a Directory in Windows? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|