#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0

IMN logo majestic logo threadwatch logo seochat tools logo