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
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With