You are here:

C/Checking the existense of a file in C

Advertisement


Question
Hi,

How to check the existance of a particular file resideing in the file system from within a C program?

I'm working on Linux platform. Do you think you can help me?

Thanks

Nivantha Gunaherath

Answer
There are many ways to do that. And I list 3 of them here:
1. Open the directory and search for the particular file.
2. Use stat() function.
3. Try to open the file in read mode and if it opens without error, then the file is existing.

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