0
如何在複製過程中排除正在複製的特定文件。我想從被複制例如name.xml的,adress.xml和data.xml中vb.net從複製中排除特定的文件名?
這裏排除是從MSDN代碼我使用:
Dim BackupDir As String = Application.StartupPath & "\backup"
Dim sourceDir As String = Application.StartupPath
If Not Directory.Exists(BackupDir) Then
IO.Directory.CreateDirectory(BackupDir)
End If
Try
Dim xmlList As String() = Directory.GetFiles(sourceDir, "*.xml")
For Each f As String In xmlList
'Remove path from the file name.
Dim fName As String = f.Substring(sourceDir.Length + 1)
File.Copy(Path.Combine(sourceDir, fName), Path.Combine(BackupDir, fName), True)
Next
Catch copyError As IOException
Console.WriteLine(copyError.Message)
End Try
史蒂夫列表執行復制前檢查的工作就像一個魅力,謝謝。剛剛將d字母添加到第一個excludeFiles中,並將c添加到第二個中:) – Chelovek
更改了IndexOf中的方法Contains。這允許傳遞枚舉來避免文件名大小寫(I.E. FILE1.xml) – Steve