Solved

Searching Files in a directory

Posted on 1998-11-18
6
188 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
posix semaphore deadlock 13 114
memory mapped I/O query 6 142
Problem with form project 66 317
Could someone please explain the following output from a linux based ldd -v  command? 6 129
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…
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 and use pointers 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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now