File.Replace throwing IOException

Posted by WebDevHobo on Stack Overflow See other posts from Stack Overflow or by WebDevHobo
Published on 2010-04-05T22:05:43Z Indexed on 2010/04/05 22:13 UTC
Read the original article Hit count: 230

Filed under:
|
|
|

I have an app that can make modify images. In some cases, this makes the filesize smaller, in some cases bigger.

The program doesn't have an option to "not replace the file if result has a bigger filesize".

So I wrote a little C# app to try and solve this.

Instead of overwriting the files, I make the app write the result to a folder under the current one and name that folder Test.

The C# app I wrote compares grabs the contents of both folders and puts the full path to the file(s) in two List objects. I then compare and replace.

The replacing isn't working however. I get the following IOException:

Unable to remove the file to be replaced

The location is on an external hard-drive, on which I have full rights.

Now, I know I can just do File.Delete and File.Move in that order, but this exception has gotten me interested in why this particular setup wont work.

Here's the source code: http://pastebin.com/4Vq82Umu

And yes, the file specified as last argument of the Replace function does exist.

© Stack Overflow or respective owner

Related posts about c#

Related posts about replace