VB.net check for existence of files and or folders


Add this to check the existence of a particular file:
Dim sFileName As String
sFileName = “C:/text1.txt”
Dim fFile As New FileInfo(sFileName)
If Not fFile.Exists Then
MessageBox.Show(“File Not Found”)
Else
MessageBox.Show(“File Found. File was created on: ” & fFile.CreationTime)
End If

Add this to check the existence of a directory:
Dim sDirName As String
sDirName = “C:/temp”
Dim dDir As New DirectoryInfo(sDirName)
If Not dDir.Exists Then
MessageBox.Show(“Directory Not Found”)
Else
MessageBox.Show(“Directory Found. Directory was last accessed on: ” & dDir.LastAccessTime)
End If