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
Printable View
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.
is there a way to do it using stat()?
Look up the man page for stat, write some code, try it out.
Quzah.
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.Quote:
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
Unless this is an intellectual excercise, I'd suggest just using find and/or grep and/or a shell script.