0
private void btn_Backup_Click(object sender, EventArgs e)
{
List<DirectoryInfo> SourceDir = this.lbox_Sources.Items.Cast<DirectoryInfo>().ToList();
List<DirectoryInfo> TargetDir = this.lbox_Targets.Items.Cast<DirectoryInfo>().ToList();
foreach (DirectoryInfo sourcedir in SourceDir)
{
foreach (DirectoryInfo targetdir in TargetDir)
{
string dateString = DateTime.Now.ToString("MM-dd-yyyy_H.mm.ss");
if (this.checkbox_zipfiles.Checked == true)
{
System.IO.Compression.ZipFile.CreateFromDirectory(sourcedir.FullName, targetdir.FullName + @"\BACKUP_" + sourcedir.Name + @"_" + dateString + @".zip");
LogBackup();
}
else
{
foreach (var file in sourcedir.GetFiles()
.Where(f => !extensionsToSkip.Contains(f.Extension) && !filesToSkip.Contains(f.FullName)).ToList())
{
file.CopyTo(targetdir.FullName + @"\" + file.Name, true);
LogBackup();
}
}
}
}
到目前爲止,我的代碼只適用於文件,如何使它適用於文件夾和子文件夾以及文件夾中的文件?只複製某些文件和文件夾的程序C#
寫拷貝遞歸函數 – TriV
[在C#中複製目錄的全部內容]的可能副本(http://stackoverflow.com/questions/58744/copy-the-entire-contents-of-a-directory-in-c-sharp) – PaulF