So i have a bit of code that uses Dos Commands to try to rename a folder. So
system("rename C:\\Users\\me\\SecondDir NewDir);
So this tries to rename SecondDir to NewDir. There is already a folder at that location called NewDir so it should fail. And it does. Im then using GetLastError to get the error code returned to ensure the problem is what i expect it to be. But it only ever returns ERROR_NO_MORE_FILES. Which isnt the error i should be getting, which is ERROR_ALREADY_EXISTS. Im assuming this is something to do with using the system command?
EDIT: I just checked and i even get ERROR_NO_MORE_FILES returned when a command is successful.
GetLastError will not return a meaningful value except in the circumstances where it is documented to do so. This is not one of them – the values you are getting are irrelevant and intended for someone else.
To rename a file from C you should use the C runtime
renamefunction not use system to invoke a rename utility.GetLastErroris only meaningful immediately after calling a Win32 function which is documented to set the thread Last Error usingSetLastError. The C equivalent iserrno, which applies to C functions.The
renamefunction returns -1 on failure and setserrno.E.g.: http://msdn.microsoft.com/en-us/library/zw5t957f(v=VS.80).aspx