473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Judge Files Exist

This my first starting a new topic in English.
I want to ask if I want to judge whether a file exists how I should do.
I program with C++.
Thank you.

Jul 30 '06 #1
1 2624
>This my first starting a new topic in English.
>I want to ask if I want to judge whether a file exists how I should do.
I program with C++.
Thank you.
Open the file (probably for reading, if that's what you intend doing
with it) with fopen(). If it works, the file exists. If it doesn't
work, the file may not exist, or you may be prohibited from accessing
it. WHY did you want to know if it exists? And remember, just
because it existed when you checked it doesn't mean it will still
exist the next time you try to open it.

There are a couple of other approaches which might get you more
information (but are generally considered to have destructive side
effects). For example, remove() it. If it succeeds, the file used
to exist. Try fopen(name, "w"). If it succeeds, either the data
in the file used to exist or you just created an empty file.

It is a feature of many operating systems that you are not allowed
to know whether certain files (e.g. those in protected directories)
exist or not, so you can't always get a completely definite answer
to this question.
Jul 30 '06 #2

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

Similar topics

8
by: Mike Smith | last post by:
If I put an old exe file on a web site and create a link to it then IE will ask "open or save to disk?" when clicked. When I create an exe with VS.NET it does not ask anything, it just tries to...
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
1
by: sword | last post by:
This my first starting a new topic in English. I want to ask if I want to judge whether a file exists how I should do. I program with C++. Thank you.
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
1
by: jamesmcdonagh | last post by:
Hi newbie using nAnt for .net 2.0. I would be happy of any help that you may be able to provide. The weird thing is that VS.net builds without a problem. And the intellisense within the object...
6
by: Boaz Ben-Porat | last post by:
Hi all I guess it is not the right group for this problem, but I can't find a Newsgroup about Setup projects. Visual studio 2005 SP1 My Setup project (.vdproj) is very simple. The project's...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
26
by: Hongyi Zhao | last post by:
Dear all, I want to judge the file's encoding system correctly, i.e., belong to utf-8, ansi, gbk, gb2312, gb18030, or iso-8859-a, and so on. Who can give me some hints on the fortran...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.