Thread: What is the header for following variables?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    83

    What is the header for following variables?

    Dear All,
    I want list all the files in directory...following program i have copied from FAQ i am getting following errors..

    error-. fatal error C1083: Cannot open include file: 'dirent.h': No such file or directory

    Code:
    #include <DIRECT.H> 
    #include <stdio.h> 
    #include <windows.h>
    #include <dirent.h>
    
    int main(void)
    {
      DIR           *d;
      struct dirent *dir;
      d = opendir(".");
      if (d)
      {
        while ((dir = readdir(d)) != NULL)
        {
          printf("%s\n", dir->d_name);
        }
    
        closedir(d);
      }
    
      return(0);
    }
    i am using VC++ compiler and windows2000 operating system..

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    readdir() is a posix (linux/unix) function. It doesn't exist in Windows. There is, instead, FindFirstFile, FindNextFile and FindClose.

    Here's the help on FindFirstFile, the rest are documented in links from this page:
    http://msdn2.microsoft.com/en-us/lib...18(VS.85).aspx

    You can also have a look in the FAQ, which has code that reads a directory in Windows (as well as Posix type systems).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > It doesn't exist in Windows.
    Windows is more screwed up than you'd think, half-ass POSIX compliant (that's an oxymoron!). Then they decided to ditch it, then not, then, then not, then, then not...

    It did exist, however it seems to have been erased -- they seem to try and abstract themselves as far away from unix as possible.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  2. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  3. Many Header Files
    By matth in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2005, 02:45 PM
  4. Variables in a header file
    By Crossbow in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2002, 11:54 AM
  5. Header files
    By borland_man in forum C++ Programming
    Replies: 14
    Last Post: 02-22-2002, 04:30 AM