Link to home
Start Free TrialLog in
Avatar of asan4
asan4

asked on

Files

Hi,

How can my program discover the filenames of all the files in the current working directory?
Avatar of akshayxx
akshayxx
Flag of United States of America image

https://www.experts-exchange.com/questions/20513419/Retrieve-the-file-listing-in-a-certain-directory.html

have a look at this discussion .. similar query ..
btw u must speciy the platform and compiler u working with
Avatar of Getch
Getch

system("dir");
Unix,

#include <dirent.h>

void listcwd(void)
{
DIR *dirp = opendir(".");
struct dirent *dp;
  if (dirp) {
    while ((dp = readdir(dirp))) {
      printf("%s\n", dp-> d_name;
    }
    closedir(dirp);
  }
}
Avatar of asan4

ASKER

Hey sorry guys,

I missed stating an important part in my question. It should read:

How can my program discover the filenames of all the files in the current working directory that match a given regular expression, such as *.doc or *.txt etc?

if u are on linux .. u can refer to manual of
fnmatch OR glob
ASKER CERTIFIED SOLUTION
Avatar of rich420
rich420

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asan4

ASKER

That did it.