Dave
Dave

Reputation: 8451

FileIO.FileSystem.CopyFile() vs System.IO.File.Copy()

I have a couple of questions about the difference between this 2 classes and these specific methods, FileIO.FileSystem.CopyFile() and System.IO.File.Copy()

At the simplest level, they both do the same thing when overloaded with sourceFile, destinationFile and bool set to true to overwrite. EG

FileIO.FileSystem.CopyFile(source, destination, True) 
System.IO.File.Copy(source, destination, True)

My two questions are

  1. What are the differences between the 2 with the overload shown because I can't find (or may be I missed the point) anything on the MSDN site.
  2. How do you (the kind person answering) know the differences when it isn't in the MSDN documentation?

Upvotes: 8

Views: 15886

Answers (4)

Dave
Dave

Reputation: 8451

After my own research, it does appear to do something not documented.

FileIO.FileSystem.CopyFile(source, destination, true) will create a folder if it doesn't exist, where as System.IO.File.Copy(source, desintation, true) doesn't and throws an exception.

It also appears that when using FileIO.FileSystem.CopyFile(source, destination, true) the reference remains in memory, so when trying to delete the new folder or file, an exception is thrown "...already in use by another process".

Upvotes: 0

Antonio Bakula
Antonio Bakula

Reputation: 20693

VisualBasic version after some checks calls System.IO.File.Copy, and I find that out by using the dotPeek, dotPeek is .NET decompiler.

Upvotes: 3

PaulB
PaulB

Reputation: 24372

A quick look at Microsoft.VisualBasic.dll in reflector shows FileIO.FileSystem.Copy does just hand over to File.Copy after doing a couple of sanity checks (file, directory exists for example) and creating the destination directory if needed.

Upvotes: 8

Martin Milan
Martin Milan

Reputation: 6390

The only difference I can see is that they have potential to raise a different list of exceptions - and I discovered that, I'm afraid, by reading the MSDN documentation :o)

Upvotes: 1

Related Questions