asan4
asked on
Files
Hi,
How can my program discover the filenames of all the files in the current working directory?
How can my program discover the filenames of all the files in the current working directory?
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);
}
}
#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);
}
}
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?
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
fnmatch OR glob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it.
have a look at this discussion .. similar query ..
btw u must speciy the platform and compiler u working with