VB.Net program to move a file from one location to another location

Here, we are going to learn how to move a file from one location to another location in VB.Net?
Submitted by Nidhi, on January 16, 2021 [Last updated : March 08, 2023]

Move a file in VB.Net

Here, we will use the Move() method of the File class to move a file from one location to another location.

Program/Source Code:

The source code to move a file from one location to another location is given below. The given program is compiled and executed successfully.

VB.Net code to move a file from one location to another location

'VB.Net program to move a file from one location to 
'another location.

Imports System.IO

Module Module1
    Sub Main()
        Try
            File.Move("source/abc.txt", "dest/abc.txt")
            Console.WriteLine("File moved successfully")

        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output

File moved successfully
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, here we moved file "abc.txt" from the "source" directory to the "dest" directory.

VB.Net File Handling Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.