Mega Code Archive

 
Categories / VB.Net / File Directory
 

Create FileInfo class

Imports System Imports System.IO Class Test     Public Shared Sub Main()         Dim path As String = "c:\MyTest.txt"         Dim fi1 As FileInfo = New FileInfo(path)         If fi1.Exists = False Then             Dim sw As StreamWriter = fi1.CreateText()             sw.WriteLine("A")             sw.WriteLine("B")             sw.WriteLine("C")             sw.Flush()             sw.Close()         End If         Dim sr As StreamReader = fi1.OpenText()         Do While sr.Peek() >= 0             Console.WriteLine(sr.ReadLine())         Loop         Try             Dim path2 As String = path + "temp"             Dim fi2 As FileInfo = New FileInfo(path2)             fi2.Delete()             fi1.CopyTo(path2)             Console.WriteLine("{0} was copied to {1}.", path, path2)             fi2.Delete()             Console.WriteLine("{0} was successfully deleted.", path2)         Catch e As Exception             Console.WriteLine("The process failed: {0}", e.ToString())         End Try     End Sub End Class