Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check the file exists

Status
Not open for further replies.

jessiejane

Programmer
Oct 29, 2009
32
US
I have a filename with Example112409.txt file in the folder.

The date changes according to the current date.

I file is palced everyday in the folder. How would I check the exists without checking the date.

Like Startswith and endwith..

Any help...
 
Code:
       Dim FileFound As Boolean = False
        For Each file As String In System.IO.Directory.GetFiles("SomeFilePath")
            If file.StartsWith("Example") AndAlso file.EndsWith(".txt") Then
                FileFound = True
                Exit For
            End If
        Next
        If FileFound Then MessageBox.Show("File Found")
 
That helps me.

How would I test whether that file is empty or not?

As the filename is Example112409.txt and I need to check with the startswith("example") and endswith(".txt") whether the file is empty or not?

Any help...
 
Here is an example. Run this code, then incorporate it into your code however you wish.
Code:
        Dim ofd As New OpenFileDialog
        ofd.ShowDialog()
        Dim fi As New System.IO.FileInfo(ofd.FileName)
        If fi.Length = 0 Then
            MessageBox.Show("File " & ofd.FileName & " is empty")
        Else
            MessageBox.Show("File " & ofd.FileName & " is " & fi.Length.ToString & " bytes long")
        End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top