c/c++ how to get the names of files from a specified directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amohammad
    New Member
    • Mar 2007
    • 8

    c/c++ how to get the names of files from a specified directory

    Hi, everyone
    I m linux user,
    Can any one please guide me that how can I get the name of files from a specified directory in a c/c++ programme.
    I does't want to use any linux command, system call ,
    suppose a directory named /test/ contains the files a11.txt, a22.txt a33.txt . I want to take these file names.

    Any idea,
    Ali Muhammad KK
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by amohammad
    Hi, everyone
    I m linux user,
    Can any one please guide me that how can I get the name of files from a specified directory in a c/c++ programme.
    I does't want to use any linux command, system call ,
    suppose a directory named /test/ contains the files a11.txt, a22.txt a33.txt . I want to take these file names.

    Any idea,
    Ali Muhammad KK
    have a look at
    http://www.opengroup.o rg/onlinepubs/007908799/xsh/readdir.html

    Comment

    • amohammad
      New Member
      • Mar 2007
      • 8

      #3
      Originally posted by horace1
      have a look at
      http://www.opengroup.o rg/onlinepubs/007908799/xsh/readdir.html
      Thanks for my first question reply,

      I have tried the exmaple given in above link for reading the file names from a folder but the following code produce error.
      if ( strcmp ( dp1->d_name , arg ) != 0 )
      continue;
      The follwing error message occured 11 times
      " dereferencing pointer to incomplete type "
      I spent 2 hours on removing this error but cannot remove , Is there any special thing that I must do for that. As the size of d_name[] is also unspecified
      Any suggetion would be appreciated
      Thank

      Ali Muhammad KK

      Comment

      • amohammad
        New Member
        • Mar 2007
        • 8

        #4
        [QUOTE=amohammad]Thanks for my first question reply,

        I have tried the exmaple given in above link for reading the file names from a folder but the following code produce error.
        if ( strcmp ( dp1->d_name , arg ) != 0 )
        continue;
        The follwing error message occured 11 times
        " dereferencing pointer to incomplete type "
        I spent 2 hours on removing this error but cannot remove , Is there any special thing that I must do for that. As the size of d_name[] is also unspecified
        Any suggetion would be appreciated
        Thanks






        Thanks to replier,
        I have solved the problem
        I spent some time on googling found the solution , this was due to not including the following header file
        <sys/dir.h>
        Thanks
        Ali Muhammad


        Ali Muhammad KK

        Comment

        Working...