Mega Code Archive

 
Categories / VB.Net / File Directory
 

FileInfo provides properties and instance methods for the creation, copying, deletion, moving, and opening of files

Imports System Imports System.IO Public Class Test     Public Shared Sub Main()         Dim path1 As String = Path.GetTempFileName()         Dim path2 As String = Path.GetTempFileName()         Dim fi As FileInfo = New FileInfo(path1)         Dim sw As StreamWriter = fi.CreateText()         sw.WriteLine("A")         sw.WriteLine("B")         sw.WriteLine("C")         sw.Flush()         sw.Close()         Try             Dim sr As StreamReader = fi.OpenText()             Do While sr.Peek() >= 0                 Console.WriteLine(sr.ReadLine())             Loop             sr.Close()             Dim fi2 As FileInfo = New FileInfo(path2)             fi2.Delete()             fi.CopyTo(path2)             Console.WriteLine("{0} was copied to {1}.", path1, 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