Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to rename a file and I am getting the file, but having a hard time renaming it. Here is my code.

C++
rename(string("c:\\Users\\DS\\Downloads\\").append(string(iter->cFileName)).c_str()myfile.txt);
Posted
Comments
Sergey Alexandrovich Kryukov 6-Oct-11 18:56pm    
It does not even compile. What did you want to rename?
--SA

First of all tell us what your problem is, do not leave it to us to figure out.

You're missing a missing a comma (,) before myfile.txt and you need to enclose myfile.txt in double apostrophes (")
 
Share this answer
 
v2
Comments
Member 7766180 6-Oct-11 19:02pm    
Thank you
Simon Bang Terkildsen 6-Oct-11 19:16pm    
My pleasure
Sergey Alexandrovich Kryukov 6-Oct-11 19:14pm    
Sure, but it might not work, as it also needs path, most likely the same as the source file, so the same "append" needed.
When a file is without path it will be created in working directory, and this directory totally depends on how the user runs the application.
(Good for simple applications, especially command line based.)
--SA
Simon Bang Terkildsen 6-Oct-11 19:15pm    
Yeah I'm aware of that, and I expected that the OP were too
It won't compile. Must be int rename ( const char * oldname, const char * newname );, http://www.cplusplus.com/reference/clibrary/cstdio/rename/[^]. Calculate two file names separately and pass to the function.

—SA
 
Share this answer
 
Comments
Member 7766180 6-Oct-11 19:02pm    
Thank you
Sergey Alexandrovich Kryukov 6-Oct-11 19:11pm    
You are welcome.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900