I am a c programmer and new to C++. In C, I am familiar with some
operations on file. Now when shifting from c to c++, using iostream, I
have no idea how to perform the following operations
1. check if a file or directory exists or not
2. delete all the files under a given directory
3. rename 15 11767
Rex_chaos wrote: I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not
Directory: no standard way to do it. Neither in C nor in C++. POSIX
provides something and Boost has a fairly portable library.
Files: again, there is no portable way AFAIK. You can try to open it. If
you can, it is there. If you cannot, it might not be there or you have no
rights or...
2. delete all the files under a given directory
No portable way. Again POSIX or Boost can help: http://www.boost.org/libs/filesystem/doc/index.htm
3. rename
std::rename, as in C.
--
WW aka Attila
> I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not
std::ifstream check("file.ext ");
if ( ! check )
std::cout << "file does not exist";
2. delete all the files under a given directory
No, unless you have the file list. Remove a single file with
std::remove("fi lename");
from <cstdio> iirc. You'll have to use some implementation-specific
functions to get more informations about the file system.
3. rename
No, except by copying under a new name and then remove the old
one.
Jonathan
Jonathan Mcdougall wrote: I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not
std::ifstream check("file.ext ");
if ( ! check ) std::cout << "file does not exist";
Which can fail for a thousand other reasons. No rights, temporary network
problem, file is opened exclusively by someone else etc. etc. etc. 3. rename
No, except by copying under a new name and then remove the old one.
How about the std::rename function in cstdio.h?
--
WW aka Attila
Jonathan Mcdougall wrote in news:Y0Efb.5836 2$1M6.1109254
@wagner.videotr on.net: I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not std::ifstream check("file.ext ");
if ( ! check ) std::cout << "file does not exist";
All this realy tells you is there was an error when you tried
to open the file for reading, It may be enough to know this but
it isn't a portable "file does not exist".
You could, having failed to open it, then try to create and write
to it, if this succeeds then the file *probably* didn't exist. 2. delete all the files under a given directory
No, unless you have the file list. Remove a single file with
std::remove("fi lename");
from <cstdio> iirc. You'll have to use some implementation-specific functions to get more informations about the file system.
3. rename
No, except by copying under a new name and then remove the old one.
int std::rename(con st char *old, const char *new); http://www.dinkumware.com/manuals/re...io.html#rename
Rob.
-- http://www.victim-prime.dsl.pipex.com/
WW wrote: How about the std::rename function in cstdio.h?
<cstdio>, no '.h'.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Kevin Goodsell wrote: WW wrote:
How about the std::rename function in cstdio.h?
<cstdio>, no '.h'.
Well said. :-)
--
WW aka Attila
> >> 3. rename No, except by copying under a new name and then remove the old one.
How about the std::rename function in cstdio.h?
That`s the second time I forget it. Sorry.
Jonathan
"Rex_chaos" <re*******@21cn .com> wrote in message
news:f7******** *************** **@posting.goog le.com... I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not
Neither C nor C++ has the capability for this.
2. delete all the files under a given directory
Neither C nor C++ has the capability for this.
3. rename
Both C and C++ have a standard function for this.
Interestingly, its name is 'rename'. (Declared
by standard header <stdio.h> in C, <stdio.h>
or <cstdio> in C++.
-Mike
"Jonathan Mcdougall" <jo************ ***@DELyahoo.ca > wrote in message
news:Y0******** *************@w agner.videotron .net... I am a c programmer and new to C++. In C, I am familiar with some operations on file. Now when shifting from c to c++, using iostream, I have no idea how to perform the following operations
1. check if a file or directory exists or not std::ifstream check("file.ext ");
if ( ! check ) std::cout << "file does not exist";
That is an invalid conclusion. The only valid conclusion
is "Cannot open the file". 2. delete all the files under a given directory No, unless you have the file list. Remove a single file with
std::remove("fi lename");
from <cstdio> iirc. You'll have to use some implementation-specific functions to get more informations about the file system.
3. rename
No,
Yes.
except by copying under a new name and then remove the old one.
See standard function 'rename()'
-Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Woojay Jeon |
last post by:
OK, I tried a Google search on this Usenet group but couldn't find a
solution, so I'm posting my question here (if there's a better archive than
the one in Google, please let me know).
Does anybody know how to detect the operating system under which the current
Python program is running, especially whether it's Windows or Unix? I have a
program that needs to search for files in "c:\test" if it's running under
Windows, and...
|
by: Mark Depenbrock |
last post by:
--Apple-Mail-2--68472726
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Can not make mysql connection -
error log:
030708 08:53:48 mysqld started
|
by: Raj |
last post by:
Hi all,
Can anyone help me with a script which would delete files or
move them to a different folder at some scheduled time..!
Please.....!!!
Thanks in advance...
|
by: Vavel |
last post by:
Hi all!
I want to insert the record into the table by
using an application program that includes the following statements:
EXEC SQL BEGIN DECLARE SECTION;
long hvInt_Stor;
long hvExt_Stor;
EXEC SQL END DECLARE SECTION;
hvInt_Stor = MMDB_STORAGE_TYPE_INTERNAL;
hvExt_Stor = MMDB_STORAGE_TYPE_EXTERNAL;
|
by: pat |
last post by:
Abraxas Software
Understanding YOUR GOALS & Using CodeCheck Implementing Corporate
Source Code Guidelines C/C++ Source Code GuideLine Automation
The goals of CodeCheck are:
1 To create a standard which will enable you to provide the customer
with a quality product in a timely manner. 2 To promote standardization
of software development among programmers. 3 To act as a learning tool
for new programmers. 4 To act as a reference tool for...
| |
by: dazza000 |
last post by:
Hi
I wan't to write a file renaming utility that is integrated with windows. for example: you open a normal folder, select one or multiple files, then hava a vb dialog box come up with new file name bases and extensions , then click a button and see the names change in the windows folder window.
I already know how to rename the files, but I am limited to using file browsing within VB.
So how do I pick up the path names of selected files...
|
by: lallous |
last post by:
Hello
If one has two operating systems on two different partitions, say
Vista and XP.
Is there is a way to install VS2005 on one partition and make it work
on both operating systems, without needing to install VS2005 on both
OSes (so that the registry is patched correctly) ?
Regards,
|
by: Fro |
last post by:
Hi,
I have a php-script which writes uploaded files into a directory. My
php-script gives a specific names to the saved files. I found in the
directory a file which has a name which could not be given by the php-
script. Could it be that somebody (which is not a user of the
operating system) communicate with the operating system (creates
files) without the usage of my php-script? Or it is impossible and I
have to search for a mistake in...
|
by: pavanip |
last post by:
Hi,
I have developed one windows application using vb.net. I have setup that application on windows operating system its working fine on windows os. Now I am trying to do that exe run on Mac operating system. Is there any other know the solution how the windows application compatible with Mac operating system.
To support vista os I created manifest file and resource script files.Please help me how the windows application compatible with...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |