473,748 Members | 8,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check whether a file exists

How can I check whether a file exists?

Jul 30 '06 #1
5 11107
"sword" <so***********@ gmail.comwrote in message
news:11******** ************@m7 3g2000cwd.googl egroups.com...
: How can I check whether a file exists?

You'll get the same answer here as in the C NG ;)

The portable way to check for this is to try to open
the file (you may use ifstream, or fopen as in C)
to check if it succeeds, then close it immediately.

Two main issues are:
- various operating systems may have various
restrictions on visibility or accessibility
of files within a given storage/directory.
- on a multitasking OS, a file that exists
at a given time may be deleted by the next
statement.

So in general, best is to just try to use the file,
and report the error at that point.
hth-Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Jul 30 '06 #2

"sword" <so***********@ gmail.comschree f in bericht
news:11******** ************@m7 3g2000cwd.googl egroups.com...
How can I check whether a file exists?
man access

John
Jul 30 '06 #3
Thanks

Jul 30 '06 #4
Bruintje Beer <me@knoware.nlw rote:
"sword" <so***********@ gmail.comschree f in bericht
news:11******** ************@m7 3g2000cwd.googl egroups.com...
>How can I check whether a file exists?
man access
Are you aware of the fact this will not lead to any solution to the
problem at all in many cases?
--
jb

(reply address in rot13, unscramble first)
Jul 30 '06 #5
Hi,

On most platforms there is a function called fstat, stat and lstat that uses
a filename, or descriptor and lets you check for various stuff about a file
(I believe it returns
'-1' if a file doesn't exist) Available on linux, solaris, windows, dec and
probably many more.
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"sword" <so***********@ gmail.comwrote in message
news:11******** ************@m7 3g2000cwd.googl egroups.com...
How can I check whether a file exists?

Jul 30 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
34744
by: newcomer | last post by:
Is there a way to check if a file exists in Javascript? This is what I'm trying to do: if(thisfile.htm exists) do this else do that
2
17897
by: adam | last post by:
hello What query shoul I send to SQL serwer ( in transact SQL language ) to check does some database exist on serwer ? It similar to problem "does some table exist in database" - resolve to it is query: use db_silnik IF EXISTS (SELECT * FROM prad) PRINT 'table exist'
10
4517
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is "ENOENT", The file doesn't exist.
7
33469
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
2
1306
by: Ponnurangam | last post by:
Hi, I need to check whether a file named flower exists with different extensions. I know only file name. I don't the the extension(may be .bmp, .ipg, or ..gif). And if there are files with different extensions, I need to get their name with extensions and copy them to a folder.
10
2720
by: kd | last post by:
Hi All, Is there a command to check whether a given string is present in a text file, without having to read the contents of the file, a line at a time and then check for the given string? Thanks. kd
3
14559
Maidenz08
by: Maidenz08 | last post by:
How do i check whether an email id exists or not? I am following a three step validation process.. 1) syntax validation- which is pretty straight forward 2) DNS validation - I'm able to do this too. 3) mailbox validation - I have read in many forums saying it is IMPOSSIBLE to check whether a particular email id exists. But take a look at this site.
0
3579
by: MIRRA | last post by:
Hi I have a UNIX script which creates a report. In that script I have to define the java classpath. Also I need to check if the java classpath specified exists or not. Below is the command i use XY=./abc/cde:./bgh/nkl # check if path defined in $jXY exists IFS=: for i in $XY do if
12
2244
by: foolsmart2005 | last post by:
There are 10 webpages on the host, e.g. 001.html, 002.html, 003,html, 004.html, ......010.html I want to check whether the page is the last page. How can I do. In the index.html -Go to last page,<---- I want to link this to the last page(010.html). Can I do it? How? Thanks!
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.