[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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
0
dba123
Asked:
dba123
  • 5
1 Solution
 
Bob LearnedCommented:
Example:
  Dim extension As String = IO.Path.GetExtension(fileName)

Bob
0
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now