Find the answer to your Linux question:
Results 1 to 3 of 3
Hi everybody, Does anyone know a clean way to get a filelisting from a given dir in linux? I need to edit multiple files in a C++ prog and I ...
  1. #1
    Pim
    Pim is offline
    Just Joined!
    Join Date
    Feb 2005
    Location
    Groningen (NL)
    Posts
    19

    reading Directory contents (files) with C++



    Hi everybody,
    Does anyone know a clean way to get a filelisting from a given dir in linux?
    I need to edit multiple files in a C++ prog and I couldn't find a solution on the net.

    Many thanx
    Pim

  2. #2
    tfk
    tfk is offline
    Linux Newbie
    Join Date
    Oct 2004
    Location
    de
    Posts
    103
    A quick into the look GNU C Library documentation always helps. :)

    http://www.gnu.org/software/libc/man...index.html#Top
    http://www.gnu.org/software/libc/man...sing-Directory

    And here's an example program (taken from the glibc doc):
    Code:
         #include <stddef.h>
         #include <stdio.h>
         #include <sys/types.h>
         #include <dirent.h>
         
         int
         main &#40;void&#41;
         &#123;
           DIR *dp;
           struct dirent *ep;
         
           dp = opendir &#40;"./"&#41;;
           if &#40;dp != NULL&#41;
             &#123;
               while &#40;ep = readdir &#40;dp&#41;&#41;
                 puts &#40;ep->d_name&#41;;
               &#40;void&#41; closedir &#40;dp&#41;;
             &#125;
           else
             perror &#40;"Couldn't open the directory"&#41;;
         
           return 0;
         &#125;
    -- Felix
    it\'s !Linux; it\'s GNU/Linux!
    [XBill] [GNU] [Viewable with Any Browser] [Drop me a mail]

  3. #3
    Pim
    Pim is offline
    Just Joined!
    Join Date
    Feb 2005
    Location
    Groningen (NL)
    Posts
    19
    thanx!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •