Link to home
Start Free TrialLog in
Avatar of jmsloan
jmsloan

asked on

Rename file in C++

I am trying to rename a file with the following code and I get a

error renaming file:  No Such File or Directory

This oldname variable does exist

any thoughts?

#include <stdio.h>

int main ()
{
  int result;
  char oldname[] ="C:\cplus\trythis.txt";
  char newname[] ="C:\cplus\newfolder\newname.txt";
  result= rename( oldname , newname );
  if (result != 0 )
    perror( "Error renaming file" );
    cout << oldname;
  return 0;
}


Thanks,

jmsloan
Avatar of imladris
imladris
Flag of Canada image

What about "newfolder"? Does that folder exist?
Avatar of jmsloan
jmsloan

ASKER

yes it does.  I'm on xp does that matter.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmsloan

ASKER

thats what it was,

Thanks