views:

50

answers:

1

Is there a way to get this code to automatically overwrite files?

// Requires project reference to Microsoft.VisualBasic
using Microsoft.VisualBasic.FileIO;
class FileProgress
{
   static void Main()
   {
      string sourcePath = @"C:\Users\public\documents\";
      string destinationPath = @"C:\testFolder";
      FileSystem.CopyDirectory(sourcePath, destinationPath,
          UIOption.AllDialogs);
   }
}

This is from MSDN

Thanks

+2  A: 

Yes.

use this overload of FileSystem.CopyDirectory to overwrite existing files:

public static void CopyDirectory(
    string sourceDirectoryName,
    string destinationDirectoryName,
    bool overwrite
)

So your code becomes:

// Requires project reference to Microsoft.VisualBasic 
using Microsoft.VisualBasic.FileIO; 
class FileProgress 
{ 
   static void Main() 
   { 
      string sourcePath = @"C:\Users\public\documents\"; 
      string destinationPath = @"C:\testFolder"; 
      FileSystem.CopyDirectory(sourcePath, destinationPath, True); 
   } 
} 
Mitch Wheat
If I use that overload, I loose the "UIOption.AllDialogs" and the built in progress bar with it. I guess I can't have my cake an eat it too. :( Thanks though.
JimDel