Solved

Searching Files in a directory

Posted on 1998-11-18
6
191 Views
Last Modified: 2010-04-15
What is the C function is used to search for files in the directory or subdirectory? Theare is a function ' stat ' for which if you give the file name we can get the information about that file whether it is ordinary file or a directory etc. Like this is there any function which searchs for the files in the directory?
0
Comment
Question by:jsreedhar
[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
  • 3
  • 2
6 Comments
 

Author Comment

by:jsreedhar
ID: 1254407
Let me know the answer as early as possible.
Thank you.
0
 

Author Comment

by:jsreedhar
ID: 1254408
Let me know the answer as early as possible,
Thank you.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1254409
1.  What operating system are you using?
2.  What exactly do you mean by "search"?  Determining if a filename exists?  Listing all files that meet certain criteria?  Listing all files in a given directory?
0
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!

 
LVL 10

Accepted Solution

by:
rbr earned 100 total points
ID: 1254410
Use opendir to open the directory structur and readdir to read ony entry. with stat (fstat) you can check the type of the entry (file or subdir).
0
 
LVL 10

Expert Comment

by:rbr
ID: 1254411
DIR *pdir
struct dirent *pentry;
struct stat stat;

pdir=opendir ("/");
while (NULL != (pentry = readdir (pdir))) {
      stat (pdir->d_name,&stat);
      if (stat.st_mode & S_IFDIR) {
            printf ("Directory: %s",pdir->d_name);
      }
}

0
 

Author Comment

by:jsreedhar
ID: 1254412
I am sorry, If I am not clear in the question. The question is like this. If I give a pattern say
' *.* ', it should list all the file names in the current directory and the sub-directories. Like in windows sdk programming we have FindFirstFile and FineNextFile which helps for doing the above. Same way is there any functions in C language. Actually I want write for both dos and unix. That is why I am using only C functions.

Thank you.
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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

752 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