Thursday, May 14, 2020

[VB][Resloved] vb CopyTo if file exist, override existing file

Source
Try
  Dim destDir As String = Path.GetDirectoryName(destFilePath)
  If (Not System.IO.Directory.Exists(destDir)) Then
    System.IO,Directory.CreateDirectory(destDir)
  End If
  Dim fr As New FileInfo(sourceFilePath)
  fr.CopyTo(destFilePath)
Catch ex As Exception
  outMessage = ex.Message
End try
Update for supporting override
Try
  Dim destDir As String = Path.GetDirectoryName(destFilePath)
  If (Not System.IO.Directory.Exists(destDir)) Then
    System.IO,Directory.CreateDirectory(destDir)
  End If
  Dim fr As New FileInfo(sourceFilePath)
  fr.CopyTo(destFilePath, True)
Catch ex As Exception
  outMessage = ex.Message
End try


Reference:
https://stackoverflow.com/questions/13406225/file-already-exist-using-system-io-file-copy

No comments :

Post a Comment