473,698 Members | 2,747 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 11098
"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
34742
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
17896
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
4509
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
33468
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
1303
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
2714
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
14552
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
3571
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
2236
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
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
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
9031
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
8876
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
6531
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
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.