有没有办法让这段代码自动覆盖文件?
// 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);
}
}
这是MSDN
由于
答案 0 :(得分:2)
是
使用FileSystem.CopyDirectory的重载来覆盖现有文件:
public static void CopyDirectory(
string sourceDirectoryName,
string destinationDirectoryName,
bool overwrite
)
所以你的代码变成了:
// 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);
}
}