This tutorial is going to teach you how to Copy, Move and Delete a file from one location to another. For this we use System.IO.File property Copy, Move and Delete. This is very useful to interact with files stored in Hard Disk. In this example, for Copy and Move take input as specific location where you file stored like "D:\Test.txt" and destination location where we want to Paste or Move file like "D:\NewText.txt". In case of Delete only specific only where the file located to delete.
Dim CopyFrom As String = "D:\Test.txt"
Dim CopyTo As String = "D:\NewText.txt"
If System.IO.File.Exists(CopyFrom) = True Then
System.IO.File.Copy(CopyFrom, CopyTo)
MsgBox("File Copied!")
End If
End Sub
Public Sub FileMove()
Dim MoveFrom As String = "D:\Test.txt"
Dim MoveTo As String = "E:\Test.txt"
If System.IO.File.Exists(MoveFrom) = True Then
System.IO.File.Move(MoveFrom, MoveTo)
MsgBox("File Moved!")
End If
End Sub
Public Sub FileDelete()
Dim DeleteFrom As String = "E:\Test.txt"
If System.IO.File.Exists(DeleteFrom) = True Then
System.IO.File.Delete(DeleteFrom)
MsgBox("File Deleted!")
End If
End Sub
No comments:
Post a Comment