Hi @ViVe_72,
You didn't explain your logic, and didn't provide samples of SSIS variables values.
I made few general improvements:
- Introduced
Path.Combine()
- Introduced
Select Case
statement. - Added error handling via
Try/Catch
statement with error logging.
Sub Main
Dim InputFilePath As String = Dts.Variables.Item("InputFilePath").Value.ToString
CreateALLFile(InputFilePath, "EALLEB.V1", "E?????EB.V*", "EB")
CreateALLFile(InputFilePath, "EALLEJ.V1", "E?????EJ.V*", "EJ")
Dts.TaskResult = ScriptResults.Success
End Sub
Private Sub CreateALLFile(ByVal folderPath As String, ByVal delfile As String, ByVal srhfile As String, ByVal fileflag As String)
Dim localFile As String
Dim fileContent As String()
Try
'Dim outputFilePath As String = folderPath + delfile
Dim outputFilePath As String = Path.Combine(folderPath, delfile)
For Each localFile In Directory.EnumerateFiles(folderPath, delfile)
File.Delete(localFile)
Next
For Each localFile In Directory.EnumerateFiles(folderPath, srhfile)
fileContent = File.ReadAllLines(localFile)
File.AppendAllLines(outputFilePath, fileContent)
Dts.Variables.Item("FileExists").Value = True
' If fileflag = "EB" Then
' Dts.Variables.Item("ebfile").Value = True
' End If
'
' If fileflag = "EJ" Then
' Dts.Variables.Item("ejfile").Value = True
' End If
Select Case fileflag
Case "EB"
Dts.Variables.Item("ebfile").Value = True
Case "EJ"
Dts.Variables.Item("ejfile").Value = True
Case Else
'???
End Select
Next
Catch ex As Exception
Dts.Events.FireError(-1, "CreateALLFile()", ex.Message, "", -1)
Dts.TaskResult = ScriptResults.Failure
End Try
End Sub