Re: find files



On Wed, 23 Jan 2002, Oliver Buecker wrote:

Hi everyone!

I have to make a C-Programm, in which the user has to select from all
files with the ending ".dat" of the Filesystem.

Does anyone know a funktion like the UNIX-Kommand "find . -name FILE"
and how I can
put the result in a list, to choose some files from it (like
gtkfileselection)?

Can someone tell me how to do this???

Start with someting like:

#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>

main()
{

    int retur;
    struct stat filinfo;
    struct dirent *filstuff;
    char filename[80];

    DIR *dirp;

    dirp = opendir("/usr/sbin");

    while( ( filstuff = readdir( dirp )) != NULL )
      {

         printf("Dirent name: %s\n", filstuff->d_name );

         bzero(filename, sizeof(filename));
         strcat(filename, "/usr/sbin/" );
         strcat(filename, filstuff->d_name );

         printf("Long filename: %s \n", filename);

         if(( retur = stat(filename, &filinfo ) ) < 0)
         {
           perror("Fel vid stat");
         }

         printf("File UID: %d\n", filinfo.st_uid);

      }

}


And go futher...

GH

----------------------------------------------------------------
Göran Hasse            email: gh raditex se     Tel: 08-6949270
Raditex AB             http://www.raditex.se
Sickla Alle 7, 1tr                              Mob: 070-5530148
131 34  NACKA, SWEDEN





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]