Imports System
Imports System.IO
Module FileExample
Sub Main()
Try
Dim originalFile As String = "test.xml"
Dim fileToReplace As String = "test2.xml"
Dim backUpOfFileToReplace As String = "test2.xml.bak"
If (File.Exists(originalFile) And (File.Exists(fileToReplace))) Then
ReplaceFile(originalFile, fileToReplace, backUpOfFileToReplace)
Else
Console.WriteLine("Either the file {0} or {1} doesn't " + "exist.", originalFile, fileToReplace)
End If
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
Sub ReplaceFile(ByVal fileToMoveAndDelete As String, ByVal fileToReplace As String, ByVal backupOfFileToReplace As String)
Dim fInfo As New FileInfo(fileToMoveAndDelete)
fInfo.Replace(fileToReplace, backupOfFileToReplace, False)
End Sub
End Module