Code to check textfile exitst in a given directory or not


It will check whether textfile starts with letter 's' is present in d: directory or not

It will check whether textfile starts with letter 's' is present in d: directory or not


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim RootPath As String = "D://"

Dim files As String()

files = Directory.GetFiles(RootPath, "s*.txt")

If (files.Length > 0) Then
MsgBox("Files Exists")
Else
MsgBox(" doesn't Exists")
End If

End Sub


Regards
Swathi


Comments

Author: Ajmal Abbasi24 Sep 2010 Member Level: Bronze   Points : 1

Following is the code to look for existence of a specific text file in a folder.
'

' folder is the name of folder where you are searching
' file is name of the file you are looking
sub find_file(byval folder as string, byval file as string)

Dim required_file as string=Directory.GetFiles(folder, file)
if required_file.length>0 then
Msgbox(file & "is found in the folder: " & folder)
else
Msgbox("No such file found in the folder" & folder)

end if
end sub



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: