Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Files

Hi,

How can my program discover the filenames of all the files in the current working directory?
0
asan4
Asked:
asan4
1 Solution
 
akshayxxCommented:
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20513419.html

have a look at this discussion .. similar query ..
btw u must speciy the platform and compiler u working with
0
 
GetchCommented:
system("dir");
0
 
ecwCommented:
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);
  }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
asan4Author Commented:
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?

0
 
akshayxxCommented:
if u are on linux .. u can refer to manual of
fnmatch OR glob
0
 
rich420Commented:
#include <setargv.obj>

This will automatically expand *.* to all the files in your directory, separated by spaces.
0
 
asan4Author Commented:
That did it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now