C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rename the filename with temp file

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
electroman
Guest





PostPosted: Sun Aug 20, 2006 5:35 am    Post subject: Rename the filename with temp file Reply with quote



Hello,

I am using Borland 5.02 C/C++ software and I am trying to find a way to
rename my save input to a temp file. My save buffer is
c:\\wsc\\Select.txt. I wish only to find a way way to rename the file
into a temp like c:\\wsc\\record.txt is an example. I need to use the
temp file over and over too. I wish that I will have
c:\\wsc\\xxxxx.txt as a constant.

Thanks,

Jim


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Jack Klein
Guest





PostPosted: Sun Aug 20, 2006 6:49 pm    Post subject: Re: Rename the filename with temp file Reply with quote



On 19 Aug 2006 20:35:20 -0400, "electroman" <jiwarner (AT) i2k (DOT) com> wrote
in comp.lang.c++.moderated:

Quote:
Hello,

I am using Borland 5.02 C/C++ software and I am trying to find a way to
rename my save input to a temp file. My save buffer is
c:\\wsc\\Select.txt. I wish only to find a way way to rename the file
into a temp like c:\\wsc\\record.txt is an example. I need to use the
temp file over and over too. I wish that I will have
c:\\wsc\\xxxxx.txt as a constant.

Thanks,

Jim

I'm sorry, I am not sure that I understand your question the way you
have worded it.

If you merely want to rename a file, C++ has a standard library
function from that, which it inherits from the C standard library.

Include either <cstdio> or <stdio.h> and use the function:

int rename(const char *old, const char *new);

....or std::rename() if you are including <cstdio>. BC++ 5.02 was
quite a bit pre-standard, and I don't think the <cxxx> headers and
namespace std for their functions worked too well, if I remember
right.

In your particular case, it sounds like you would want:

int result = rename("c:\\wsc\\Select.txt",
"c:\\wse\\record.txt");

The returned value is 0 if the operation is successful, and non zero
if it fails for any reason.

Most of the details of why the function succeeds or fails are platform
specific and not defined by the C standard, but I would suggest that
you do not have the file open when you try to rename it. On most
versions of Windows that would probably cause the rename to fail.

Note that the two parameters to rename() do not have to be string
literals, they can be strings that you put together at run time.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.