help-gplusplus
[Top][All Lists]
Advanced

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

Re: Listing the files in a directory.


From: Alex Vinokur
Subject: Re: Listing the files in a directory.
Date: Mon, 5 Jul 2004 18:04:09 +0300

"SK" <sk_ind12@rediffmail.com> wrote in message 
83dee709.0407050637.67d27504@posting.google.com">news:83dee709.0407050637.67d27504@posting.google.com...
> Hi all,
>
> I know that it's implementation specific to find the files in a given
> directory. I want to know how it is done with g++ (the way
> FindFistFile etc do in VC++).
>
> Thanks.

GNU gcc version 3.3.1 (cygming special)

--------- foo.c ---------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

void find_all_files_in_dir()
{
FILE*           fp;
const char      cmd [] = "ls";

#define  SIZEBUF 1024
char            buf [SIZEBUF];

  if ((fp = popen(cmd, "r")) == NULL)
  {
    printf ("Files or processes cannot be created\n");
    exit (1);
  }

  while (fgets(buf, sizeof(buf), fp))
  {
    assert (strlen(buf) < sizeof(buf));
    printf ("%s", buf);
  }

  if (pclose(fp) == -1)
  {
    printf ("Cannot do pclose\n");
    exit (1);
  }
}

int main ()
{
  find_all_files_in_dir ();
  return 0;
}

-------------------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]