Finding files in a directory that begin with string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • datamonk
    New Member
    • Aug 2007
    • 2

    Finding files in a directory that begin with string

    I am working on a package in SSIS that needs to check a directory to see if any files that begin with a three character string (PDE) exist, and set the value of a variable accordingly to determine which path the package should follow next.

    Here is the code I am using. I found it on a similar thread in this forum. The code runs without error but does not update the variable to 1 when a file exists. Any suggestions?

    [CODE=vbnet]
    Dim AllFiles() As String = System.IO.Direc tory.GetFiles(" \\fcfpsvr1\shar e\medicare\bipi mport\incomingf iles\", "*.txt")

    Dim I As Integer

    For I = 0 To AllFiles.Length - 1
    If AllFiles(I).Sta rtsWith("PDE") Then
    System.Diagnost ics.Debug.Write Line(AllFiles(I ))
    Dts.Variables(" SourceFileExist s").Value = 1
    End If
    Next[/CODE]
  • datamonk
    New Member
    • Aug 2007
    • 2

    #2
    Ah, resolved the issue. The file pathway was included as part of the filename, changing the .StartsWith() to .Contains() solved the problem.

    Originally posted by datamonk
    ...
    If AllFiles(I).Sta rtsWith("PDE") Then

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by datamonk
      Ah, resolved the issue. The file pathway was included as part of the filename, changing the .StartsWith() to .Contains() solved the problem.
      I suspect you could also shortcut the process like so...
      [CODE=vbnet]Dim AllFiles() As String = System.IO.Direc tory.GetFiles(" \\fcfpsvr1\shar e\medicare\bipi mport\incomingf iles\ ", "PDE*.txt")[/CODE]

      Comment

      Working...