Wednesday, May 21, 2008

"There is no such method!" That's what everyone is told by Microsoft. Microsoft is even insolent enough to provide us with reasons why they did not include Directory.Copy method in .NET Framework.

I find those arguments unacceptable. Sure, they are valid at some level, but it's wouldn't be the only piece of code that goes "mainstream" and does what 99% of people would expect it to do, without considering special cases.

So I went and almost implemented my own Directory.Copy. Almost.

It came out that Microsoft does not live to its own words! There is a method in .NET Framework, that allow us to copy a directory, just like that, in one call. It is hidden in a Microsoft.VisualBasic.dll assembly in a Microsoft.VisualBasic.FileIO.FileSystem type and is called (not surprisingly) CopyDirectory.

Although it is in VisualBasic namespace, there is nothing that prevents us from using it in C#. Only a reference to an assembly is needed.

Well Microsoft? What you say to that?