mohamedsamir3000
New member
- Joined
- Sep 20, 2011
- Messages
- 2
- Programming Experience
- 3-5
How can I replace a file with another one with the same name by Code?
I haven't tested this but it should work finetry
'Source file
Dim sFile As String = "C:\Source.File.exe"
'Destination File
Dim dFile As String = "C:\Destination.File.exe"
'Backup File *Optional*
Dim bFile As String = "C:\BakupFile.exe"
'Check File *Not needed* you could use "sfile"
Dim cFile As String = "C:\SomeFile.exe"
'check if file is Exsisting
If IO.File.Exists(cFile) = True Then
'File Replaced
IO.File.Replace(sFile, dFile, bFile)
'Line Bellow using the True Boolean in
'the last part is a Overwite method with out Backing up
'IO.File.Copy(sFile, dFile, True)
Else
'File Copied
IO.File.Copy(sFile, dFile)
End If
Catch ex as exception
end try