Check extension of incoming file in If statement

I'm trying to check the extension tye of the incoming file.  The problem lies here:

The code:

    Sub Main()

        ProcessFiles("\\sss\\sss_input.txt", "\\sss\mnt_output\")
        'ProcessFiles("\\sss\naf_input.mer", "\\sss\naf_output\")

    End Sub

    Public Sub ProcessFiles(ByVal sIncomingfile As String, ByVal sOutputDirectory As String)
        Dim f As New Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.None)
        f.AllLocalFiles = Security.Permissions.FileIOPermissionAccess.Read

        Dim file As New IO.FileInfo(sIncomingfile)

        Dim filefs As New IO.FileStream(file.FullName, IO.FileMode.Open)
        Dim reader As New IO.StreamReader(filefs)
        Dim counter As Integer = 0

        Dim CurrentFS As IO.FileStream
        Dim CurrentWriter As IO.StreamWriter

        If file.FullName.Substring(Len(sIncomingfile), -3) = ".txt" Then  <---------------- MALFORMED HERE
            While Not reader.Peek < 0
                Dim Line As String = reader.ReadLine
                If IsNumeric(Line.Substring(0, 1)) Then
                    Dim Parts() As String = Line.Split(" "c)
                    If Parts(0).Length = 8 Then
                        counter += 1
                        If Not CurrentWriter Is Nothing Then CurrentWriter.Flush() : CurrentWriter.Close()
                        CurrentFS = New IO.FileStream(IO.Path.Combine(IO.Path.GetDirectoryName(sOutputDirectory), Line.Substring(59, 4) & "[" & counter.ToString & "]" & Now.ToString("MM-dd-yyyy") & IO.Path.GetExtension(file.FullName)), IO.FileMode.Create)
                        CurrentWriter = New IO.StreamWriter(CurrentFS)
                    End If

                    If Not CurrentWriter Is Nothing Then
                        CurrentWriter.WriteLine(Line)
                    End If

                End If
            End While

            If Not CurrentWriter Is Nothing Then CurrentWriter.Flush() : CurrentWriter.Close()
            'Console.Read()

            MoveFiles(sOutputDirectory)

        Else
               ---DO SOMETHING, I'LL CODE THIS LATER
        End If
    End Sub
LVL 1
dba123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Example:
  Dim extension As String = IO.Path.GetExtension(fileName)

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dba123Author Commented:
Thanks Bob, didn't know I could do that yet!
0
dba123Author Commented:
I get the Error: Length cannot be less than zero.

       Dim f As New Security.Permissions.FileIOPermission(Security.Permissions.PermissionState.None)
        f.AllLocalFiles = Security.Permissions.FileIOPermissionAccess.Read

        Dim file As New IO.FileInfo(sIncomingfile)

        Dim filefs As New IO.FileStream(file.FullName, IO.FileMode.Open)
        Dim reader As New IO.StreamReader(filefs)
        Dim counter As Integer = 0

        Dim CurrentFS As IO.FileStream
        Dim CurrentWriter As IO.StreamWriter
        Dim extension As String = IO.Path.GetExtension(file.FullName)

        If file.FullName.Substring(Len(extension), -3) = ".mnt" Then
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

dba123Author Commented:
hold on, let me write out extension to a msgbox before you reply to see what's going on.
0
dba123Author Commented:
well, it's working, the MsgBox returned .mnt so I don't need anything but extension now.  Thanks Bob!
0
dba123Author Commented:
Dim extension As String = IO.Path.GetExtension(file.FullName)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.