473,614 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2648
>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
6667
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 run it. Is there a bit I can set somewhere that will tell IE to treat this like a "classic" exe? It make is kind of hard to create setup.exe style applications using VS.NET with this default behavior. Mike
58
4653
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 (PHONE_LIST, "_+")) { Console.WriteLine (phoneNumber); } } Output: 495.1000
1
386
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
7590
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
6168
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 WorkQueue knows that Master is referring to the PanelManager reference. nant file ------------------------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?>...
6
5798
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 output (msi package) contain one EXE and three DLLs (created in C#) that should be copied to an existing folder, where an older version already exist. The installer should replace these files with the new ones.
4
2526
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 checked. Now what the script does is it checks the time stamp and creates a year folder if it does not exist and then creates a month folder if it does not exist and puts the respective files in the month folders. If the files are created this month then it...
26
2019
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 implimentation of this issue? Thanks in advance.
0
8120
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
8620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
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...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
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
6085
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...
1
2560
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
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1420
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.