如何在复制过程中排除正在复制的特定文件。我想排除被复制,例如 name.xml、adress.xml 和 data.xml
这是我使用的 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