Thread: Directory reading

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Unhappy Directory reading

    Hello fellow programmers,
    I am having a problem running across a method of opening, reading filenames, and closing a directory in order to pull filenames with a certain extension from. In searching, the only reference I found to accomplish such a task was on the delorie/djgpp website. I am using Dev-C++ version 4.9.7.6. On the web site, they posted an example program to explain how it was used. Just for my sake, I tried the program and got some errors. Following is the program code and the errors. I am not asking for anybody to write my code, just for some knowledge in determining where the problem is.

    Code:
    /*****************CODE**************************/
    #include <sys/types.h>
    #include <dirent.h>		/* Directory information.*/
    
    main()
    {
      DIR * dir_p;
      struct dirent * dir_entry_p;
       
    			/* Open the current directory*/	
      dir_p = opendir(".");
    
    			/* read each entry until NULL.*/
    
      while( NULL != (dir_entry_p = readdir(dir_p)))
      {
    		/* print the name of the file held in 
    		 * this directory entry.*/
    
        printf(" %s \n", dir_entry_p->d_name);
      }
    
    				/* Tidy up.*/
      closedir(dir_p);
    }
    ****************ERRORS****************************
    [Linker error] undefined reference to `opendir'
    [Linker error] undefined reference to `readdir'
    [Linker error] undefined reference to `closedir'
    ************************************************** *

    The code is exactly how it was downloaded as a file. I am just doing some testing in order to determine how to implement in to my own program. Any help would be greatly appreciated.

    Thankfully,
    Kendal

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Any Ideas?????

    For some reason on my system it does not work.
    Like I said I get the following errors:

    [Linker error] undefined reference to `opendir'
    [Linker error] undefined reference to `readdir'
    [Linker error] undefined reference to `closedir'

    I am using Dev-C++, the latest version 4.9.7.6 and checked the dirent.h header file and it does make reference to opendir, readdir, and closedir. Any ideas why I get such a linker error??? Would you like to see my dirent.h header file???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-19-2005, 03:01 PM
  2. How to tell if its a file or a directory
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 11:27 PM
  3. open directory and copy files
    By 5n4k3 in forum C++ Programming
    Replies: 3
    Last Post: 08-06-2003, 09:49 AM
  4. phone book directory 2
    By arangawawa in forum C Programming
    Replies: 4
    Last Post: 08-01-2003, 05:32 PM
  5. Replies: 6
    Last Post: 07-30-2003, 03:08 AM