Solved

Searching Files in a directory

Posted on 1998-11-18
6
189 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to define a string array with big size in c language 10 138
Unable to start eclipse ? 17 142
C Programming - If Statement 8 80
Why isn't object file created? 6 61
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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

825 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