Renaming files in C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2004
Posts: 23
Reputation: iamboredguy is an unknown quantity at this point 
Solved Threads: 0
iamboredguy's Avatar
iamboredguy iamboredguy is offline Offline
Newbie Poster

Renaming files in C++

 
0
  #1
Aug 31st, 2004
I'm trying to use sequential binary file editing in C++. I use a temporary file. I have to make the changes in the file by storing the modified data in the temp file. Then I delete the original file and rename the temp as the original. The problem is the remove() and rename() functions in <fstream.h> don't seem to be working. When I check in the folder after execution, the temp file is still there and so is the original file. Does any1 know an alternative method to remove and rename a file during runtime?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,372
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Renaming files in C++

 
0
  #2
Aug 31st, 2004
Originally Posted by iamboredguy
I'm trying to use sequential binary file editing in C++. I use a temporary file. I have to make the changes in the file by storing the modified data in the temp file. Then I delete the original file and rename the temp as the original. The problem is the remove() and rename() functions in <fstream.h> don't seem to be working. When I check in the folder after execution, the temp file is still there and so is the original file. Does any1 know an alternative method to remove and rename a file during runtime?
Do you have a code sample that demonstrates the problem? Are you checking return values?
http://www.cplusplus.com/ref/cstdio/rename.html
http://www.cplusplus.com/ref/cstdio/remove.html
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 23
Reputation: iamboredguy is an unknown quantity at this point 
Solved Threads: 0
iamboredguy's Avatar
iamboredguy iamboredguy is offline Offline
Newbie Poster

It Worked!

 
0
  #3
Sep 1st, 2004
I didn't know I had to close all variables connected to the file to be deleted. It worked after I did that. Thanks a ton Dave.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC