You are here:

C/Hi. Is there some way to look...

Advertisement


Question
Hi. Is there some way to look for directories using C language? I'm trying to find out, but it's being very hard. I'm developing a simple program and I would like to enter a directory name that it'll search and if it's found, it'll be changed by the C program, otherwise I'll see a message "directory not found". I would like to do the same with file search. I'm looking for a Linux and Windows solution.
Thank you.

Answer
The same way you deal with files.
There is a header file "dirent.h" for this.
Like FILE, there is a DIR, which you have to open the directory handle.
The APIs to be used are:
opendir(), closedir(), readdir() etc.
The man pages are awailable on all the linux machines.
You can find these also on the web.
I am not sure about windows platform.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.