Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveFileEx Help!

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
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
 
From the MSDN Library:

(MoveFileEx)
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.
<end MSDN Library>

So the fact MoveFileEx returns nonzero means it was successful. You have no problem !
The GetLastError value is probably from a previous call to another function. You should only call GetLastError after a function returning a failure, or when the MSDN library tells you to do so when a function was successful.


Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top