Exception message on File.Move not correct

R

Rene

Hi,

Maybe I'm wrong, but we get an exceptoin on File.Move ("FileA", "FileB" )
because FileA is still in use (sharing violation), but the Exception.Message
says:

Process cannot access the file "FileB" because it is being used by another
process.

The destination FileB does even not exists, seems to me a wrong message,
not?


try

{

File.Move ( ("FileA",, "FileB");

break;

}

catch ( Exception E )

{

WriteLogMessage ("Move not successful " + E.Message );

}
 
J

Justin Rogers

The code for File.Move doesn't make a separate check after an attempt at
Win32.MoveFile to determine which file was in use. The error code returned
is that some file was in use, and then they attach the destination file name
explicitly to the exception.

It appears to be a bug, and since you are eating the cost of an exception anyway
you might as well do the extra work to determine which file was actually in use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top