FileInfo.MoveTo failure modes

  • Thread starter Thread starter planb
  • Start date Start date
P

planb

Hello,

I'm looking for documentation on how FileInfo.MoveTo acts when it
fails -- in particular I want to know if it's possible to end up with
the file in both locations.

I've searched MSDN and used google, but apparently my search skills
aren't up to the task...
 
I'm looking for documentation on how FileInfo.MoveTo acts when it
fails -- in particular I want to know if it's possible to end up with
the file in both locations.

Possible? Sure. It's impossible to prevent. But it shouldn't be a
common problem.

There's the basic need for an API like that to fail gracefully, without
leaving you in some indeterminate state. So I think it's probably safe
to assume it will try to do so when possible. Beyond that, moving a
file within the same volume doesn't really copy any data. It just
changes the directory information so that the file is listed in the new
location with the new name.

Even in the case where a file is being moved across volumes, I would
expect that should something fail when trying to write the new copy to
the new volume, FileInfo will try to delete the new copy. You could of
course test this scenario yourself to verify, if it's important.

Of course, if the reason that the move failed is that somehow the
destination volume got disconnected or something like that, then it
won't be available to attempt to delete the partially-generated file.
The simplest example would be moving a file from a hard disk to a
floppy, and the user ejects the floppy before the move has finished.
Obviously once that's happened, there's going to be some data on the
floppy related to the move that hasn't been deleted even though the
move failed.

But i/o errors like that should be uncommon. More typical would be
failures that prevent the move from starting in the first place and of
course those won't lead to a double-file issue.

Pete
 
Back
Top