Hello,
I have the path and the filename to be searched.
then how do I go and search for that file in that dir path using a C program.
Can somebody show me how?
Thanks
RN
Hello,
I have the path and the filename to be searched.
then how do I go and search for that file in that dir path using a C program.
Can somebody show me how?
Thanks
RN
Use the FAQ, Luke!
Quzah.
Hope is the first step on the road to disappointment.
is there a way to do it using stat()?
Look up the man page for stat, write some code, try it out.
Quzah.
Hope is the first step on the road to disappointment.
From your original question, you seem to just want to see if a file exists within a certain directory, yes?
If that's the case, you could try opening it (fopen) and seeing if you get an error indicating the file does not exist.
All stat does is produce additional information about the file, but you already need the filename to use stat.
Of course, you might be able to stat a file, but might not be able to open it, depending on permissions.
What OS?
Not sure if I got your question right, goiing on cwr's lines:
Under UNIX (most flavours), you can useto check if a file exists.Code:access()
On my computer, access() is the same speed as stat (very slow), and stat gives you more information.
Do you have a pattern? If so, try using REs.Hello,
I have the path and the filename to be searched.
then how do I go and search for that file in that dir path using a C program.
Can somebody show me how?
Thanks
RN
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Unless this is an intellectual excercise, I'd suggest just using find and/or grep and/or a shell script.
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.
Useful resources:
comp.lang.c FAQ | C++ FQA Lite