Exception message on File.Move not correct

  • Thread starter Thread starter Rene
  • Start date Start date
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 );

}
 
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.
 
Back
Top