Mega Code Archive

 
Categories / VB.Net / File Directory
 

File Move moves a specified file to a new location, providing the option to specify a new file name

Imports System Imports System.IO Imports System.Text Public Class Test     Public Shared Sub Main()         Dim path As String = "c:\temp\MyTest.txt"         Dim path2 As String = "c:\temp2\MyTest.txt"         Try             If File.Exists(path) = False Then                 Dim fs As FileStream = File.Create(path)                 fs.Close()             End If             If File.Exists(path2) Then                 File.Delete(path2)             End If             File.Move(path, path2)             Console.WriteLine("{0} moved to {1}", path, path2)             If File.Exists(path) Then                 Console.WriteLine("The original file still exists, which is unexpected.")             Else                 Console.WriteLine("The original file no longer exists, which is expected.")             End If         Catch e As Exception             Console.WriteLine("The process failed: {0}", e.ToString())         End Try     End Sub End Class