CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    17

    Renaming file in C++ failing

    I have a C++ program running on Windows XP compiled with Visual C++ 6.0 containing the following code
    Code:
    if (remove(NewName) != 0)
    {
    errmsg = strerror(errno);
    printf("Removal Error: %s\n", errmsg);
    }
    
    
    if (rename(FileName,NewName) != 0)
    {
    errmsg = strerror(errno);
    printf("Rename Error: %s\n", errmsg);
    }
    and this fails, offering to send a message to Microsoft about the error of my ways.
    The file I want to rename(FileName) does exist and the file I want to rename it to(NewName) does not and none of my error messages appear.
    Please make suggestions on how I should fix this.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Renaming file in C++ failing

    Quote Originally Posted by straygrey View Post
    I have a C++ program running on Windows XP compiled with Visual C++ 6.0 containing the following code
    Show us a full program, not just a snippet of a larger program. We have no idea where those variables come from, how they're initialized, whether you've corrupted something else that's causing the problem, etc.

    Also, you can easily test this by hardcoding the names of the files you want to delete. In other words, don't use variables, use the actual names of the file in the function call. Then if that works, then the problem is with your variables.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Oct 2008
    Posts
    17

    Re: Renaming file in C++ failing

    Name files as arrays not pointers.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Renaming file in C++ failing

    Quote Originally Posted by straygrey View Post
    Name files as arrays not pointers.
    Please show the real code, don't describe. You can corrupt programs using arrays as well as pointers.

    Secondly, and again, did you try hardcoding the names into that code and seeing if the files are deleted?. That should have been the first thing to test.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured