How to check whether file exists or not
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > How to check whether file exists or not




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    How to check whether file exists or not  
niraj.kumar.ait@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-29-05 07:48 AM

How to check whether a file exists or not at its speciefied location
.Is there any system call for this

TIA
Niraj






[ Post a follow-up to this message ]



    Re: How to check whether file exists or not  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-29-05 07:48 AM

On 28 Jun 2005 22:46:23 -0700, niraj.kumar.ait@gmail.com
<niraj.kumar.ait@gmail.com> wrote:
> How to check whether a file exists or not at its speciefied location
> .Is there any system call for this
>
stat


--
Tonight you will pay the wages of sin; Don't forget to leave a tip.





[ Post a follow-up to this message ]



    Re: How to check whether file exists or not  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-29-05 07:48 AM

niraj.kumar.ait@gmail.com wrote:
# How to check whether a file exists or not at its speciefied location
# .Is there any system call for this

Within a C program you can use access or stat
man 2 access
man 2 stat


In a shell script, you can use variants of test (or [...])

$ touch Q
$ if [ -e Q ]; then echo est; else echo non; fi
est
$ if [ -e QX ]; then echo est; else echo non; fi
non

man 1 test
--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.





[ Post a follow-up to this message ]



    Re: How to check whether file exists or not  
William Ahern


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-29-05 12:53 PM

niraj.kumar.ait@gmail.com wrote:
> How to check whether a file exists or not at its speciefied location
> .Is there any system call for this

There's stat(2), as other's have mentioned. Also access(2). You can also
just try to open the file using fopen(3) or open(2). In fact, if your
intention is to open the file if it exists than simply open it, otherwise
you have a race condition and/or are doing duplicate work.

- Bill





[ Post a follow-up to this message ]



    Re: How to check whether file exists or not  
Rich Teer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-29-05 10:53 PM

On Tue, 28 Jun 2005 niraj.kumar.ait@gmail.com wrote:

> How to check whether a file exists or not at its speciefied location
> .Is there any system call for this

You can use access(), stat(), or open() to check for a file's existance,
but if you plan to check for a file existance before opening, beware that
this introduces a race condition to your program.  In this instance, it's
better to just open() the file and deal with any errors.

HTH,

--
Rich Teer, SCNA, SCSA, OpenSolaris CAB member

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-group.com/rich





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:43 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register