rename() and remove()
Hi,
I'm trying to rename an existing file then delete it. However I doesn't work, I get the following output:
Error deleting new file : No such file or directory |
1 2 3 4 5 6 7 8 9 10 11 12
|
if(rename("old.txt", "new.txt"))
{
if(remove("new.txt") != 0)
{
perror("Error deleting new file ");
}
}
else
{
//renaming failed
perror("Error renaming old to new ");
}
|
It's confusing because if the file wasn't renamed,
Error renaming old to new |
should print out. But rename was successful, then how come no file with the name exist?
Last edited on
rename returns 0 on success. if line 3 is reached, rename was not successful.
Topic archived. No new replies allowed.