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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveFileEx returns ERROR_SHARING_VIOLATION 1

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
I use MoveFileEx to move an existing file from one folder to another.

if ( ::MoveFileEx(originalFilepath, renamedFileName,
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) )
{
LogEvent(“error”);
return “something”;
}

Sometimes when I call this function I get the following error:

GetLastError returns 0x20: The process cannot access the file because it is being used by another process.

What could cause this, and is there anyway I could tell what process has a lock on my file?

More importantly, the file seems to be partially or fully moved to its destination, even though the function returns an error. Could this be possible?

Thanks
Milton
 
the file could be used by some other application of you maybe don't have enough rithgs to move it.

Ion Filipski
1c.bmp
 
Thanks Ion,

Will that therefore mean that the file could have been partially copied to its destination before MoveFileEx flagged an error?
 
maybe. You may try to use CopyFile/DeleteFile instead. Anyway, share violation most oftem means the fiole is opened by other application or is open inside your own application and is not closed before move operation.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top