?
Solved

Files

Posted on 2003-03-31
7
Medium Priority
?
201 Views
Last Modified: 2010-04-15
Hi,

How can my program discover the filenames of all the files in the current working directory?
0
Comment
Question by:asan4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:akshayxx
ID: 8237857
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
 

Expert Comment

by:Getch
ID: 8239157
system("dir");
0
 
LVL 5

Expert Comment

by:ecw
ID: 8240324
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
Technology Partners: 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!

 

Author Comment

by:asan4
ID: 8249632
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
 
LVL 8

Expert Comment

by:akshayxx
ID: 8250192
if u are on linux .. u can refer to manual of
fnmatch OR glob
0
 

Accepted Solution

by:
rich420 earned 300 total points
ID: 8281562
#include <setargv.obj>

This will automatically expand *.* to all the files in your directory, separated by spaces.
0
 

Author Comment

by:asan4
ID: 8281581
That did it.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question