#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    London
    Posts
    2
    Rep Power
    0

    Angry Help ! MoveFileEx Problem


    I have a piece of code that renames a file from A.ACK.tmp to A.ACK in the same directory (C:\abc). Meanwhile there is another process that polls C:\abc, looking for files with a .ACK extension. Once it sees such a file, it moves it to folder D:\ABC.

    To rename the file I do the following

    if ( !::MoveFileEx(tmpRnFile, RenamedFileName,
    MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) )
    {
    LogEvent(EVMSG_SENT_FAILED, tmpRnFile, RenamedFileName, GetLastErrorString() );
    return EVMSG_SENT_FAILED;
    }

    Where tmpRnFile = C:\abc\A.ACK.tmp and RenamedFileName = c:\abc\A.ACK

    The problem I have is that MoveFileEx returns a nonzero value - GetLastError returns 0x2: The system cannot find the file specified.

    Please can anyone help? How does a move process work in NT, and can another process move or delete a file during the rename process?

    What other rename method can I use to ensure that I dont get this problem.

    Thanks
    Milton
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,184
    Rep Power
    2222
    Just a stupid question that might solve the problem:
    When you assign the file name, are you using single or double back-slashes? I.e., you say that tmpRnFile = C:\abc\A.ACK.tmp and RenamedFileName = c:\abc\A.ACK.
    But did you actually write them that way or did you write them as "C:\\abc\\A.ACK.tmp" and "c:\\abc\\A.ACK"?.

    In C/C++, the back-slash is used in character and string literals as an "escape" with which to represent special characters, like the new-line ('\n') or the NUL ('\0') or a quote mark embedded within the string (eg, "This is an example of \"embedded\" quote marks."). Therefore, to represent an actual backslash in a string literal, you need to enter it twice as I had done in my question above.

    Hope that's all it was. If it's any consolation, I've been bitten by the same thing before.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    London
    Posts
    2
    Rep Power
    0
    Sorry, my mistake, I actually used "C:\\abc\\A.ACK.tmp" and "c:\\abc\\A.ACK"?.

IMN logo majestic logo threadwatch logo seochat tools logo