How to check for file name

ICW

Active member
Joined
Mar 27, 2006
Messages
25
Programming Experience
Beginner
I have some code (see below) in my SSIS package.
Can anyone show me how to create a variable in the code that has the Vaue "HEADER" and then to only do the file.move stuff if the filename contains the string "HEADER".
I know what i want to do but lack programming skills to write the syntax.
If someone could just put in the one or two lines of code required it would really help me to learn



VB.NET:
Imports System.IO
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

	' The execution engine calls this method when the task executes.
	' To access the object model, use the Dts object. Connections, variables, events,
	' and logging features are available as static members of the Dts class.
	' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
	' 
	' To open Code and Text Editor Help, press F1.
	' To open Object Browser, press Ctrl+Alt+J.

	Public Sub Main()
        Try
            File.Move(Dts.Variables("Source").Value.ToString, Dts.Variables("Destination").Value.ToString)
            Dts.Events.FireInformation(0, "", "File Moved Succesfully", "", 0, True)
        Catch ex As Exception
            Dts.Events.FireError(1, "", "Source file or destinations does not exist", "", 0)
        End Try

        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class
 
last time i id homework was about 25 years ago:O)
I'm a 43 year old stressed worker, being given projects and deadlines that are a bit beyond what i can do by myself, hence the need to learn quickly.
Thanks In advance if anyone can help
 
Ha ha.. nice answer.. Here you go:

VB.NET:
Imports System.IO
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

[B]  Private _lookFor as String = "HEADER"[/B]

	' The execution engine calls this method when the task executes.
	' To access the object model, use the Dts object. Connections, variables, events,
	' and logging features are available as static members of the Dts class.
	' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
	' 
	' To open Code and Text Editor Help, press F1.
	' To open Object Browser, press Ctrl+Alt+J.

	Public Sub Main()
        Try
  [B]If Dts.Variables("Source").Value.ToString().Contains(_lookFor) Then[/B]
            File.Move(Dts.Variables("Source").Value.ToString, Dts.Variables("Destination").Value.ToString)
            Dts.Events.FireInformation(0, "", "File Moved Succesfully", "", 0, True)
  [B]Else
    Dts.Events.FireError(1, "", "The filename doesnt contain " & _lookFor, "", 0)
  End If[/B]
        Catch ex As Exception
            Dts.Events.FireError(1, "", "Source file or destinations does not exist", "", 0)
        End Try

        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class

I even put some error handling in there. Have a look, hope it helps
 
Back
Top