|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Sorry, my mistake, I actually used "C:\\abc\\A.ACK.tmp" and "c:\\abc\\A.ACK"?.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Help ! MoveFileEx Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|