dba123
asked on
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_i nput.txt", "\\sss\mnt_output\")
'ProcessFiles("\\sss\naf_i nput.mer", "\\sss\naf_output\")
End Sub
Public Sub ProcessFiles(ByVal sIncomingfile As String, ByVal sOutputDirectory As String)
Dim f As New Security.Permissions.FileI OPermissio n(Security .Permissio ns.Permiss ionState.N one)
f.AllLocalFiles = Security.Permissions.FileI OPermissio nAccess.Re ad
Dim file As New IO.FileInfo(sIncomingfile)
Dim filefs As New IO.FileStream(file.FullNam e, 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(Le n(sIncomin gfile), -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.Comb ine(IO.Pat h.GetDirec toryName(s OutputDire ctory), 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(Li ne)
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
The code:
Sub Main()
ProcessFiles("\\sss\\sss_i
'ProcessFiles("\\sss\naf_i
End Sub
Public Sub ProcessFiles(ByVal sIncomingfile As String, ByVal sOutputDirectory As String)
Dim f As New Security.Permissions.FileI
f.AllLocalFiles = Security.Permissions.FileI
Dim file As New IO.FileInfo(sIncomingfile)
Dim filefs As New IO.FileStream(file.FullNam
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(Le
While Not reader.Peek < 0
Dim Line As String = reader.ReadLine
If IsNumeric(Line.Substring(0
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.Comb
CurrentWriter = New IO.StreamWriter(CurrentFS)
End If
If Not CurrentWriter Is Nothing Then
CurrentWriter.WriteLine(Li
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get the Error: Length cannot be less than zero.
Dim f As New Security.Permissions.FileI OPermissio n(Security .Permissio ns.Permiss ionState.N one)
f.AllLocalFiles = Security.Permissions.FileI OPermissio nAccess.Re ad
Dim file As New IO.FileInfo(sIncomingfile)
Dim filefs As New IO.FileStream(file.FullNam e, 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(Le n(extensio n), -3) = ".mnt" Then
Dim f As New Security.Permissions.FileI
f.AllLocalFiles = Security.Permissions.FileI
Dim file As New IO.FileInfo(sIncomingfile)
Dim filefs As New IO.FileStream(file.FullNam
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.
If file.FullName.Substring(Le
ASKER
hold on, let me write out extension to a msgbox before you reply to see what's going on.
ASKER
well, it's working, the MsgBox returned .mnt so I don't need anything but extension now. Thanks Bob!
ASKER
Dim extension As String = IO.Path.GetExtension(file. FullName)
ASKER