Connecting Tech Pros Worldwide Forums | Help | Site Map

Finding files in a directory that begin with string

Newbie
 
Join Date: Aug 2007
Location: PDX
Posts: 2
#1: Aug 3 '07
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?

Expand|Select|Wrap|Line Numbers
  1.         Dim AllFiles() As String = System.IO.Directory.GetFiles("\\fcfpsvr1\share\medicare\bipimport\incomingfiles\", "*.txt")
  2.  
  3.         Dim I As Integer
  4.  
  5.         For I = 0 To AllFiles.Length - 1
  6.             If AllFiles(I).StartsWith("PDE") Then
  7.                 System.Diagnostics.Debug.WriteLine(AllFiles(I))
  8.                 Dts.Variables("SourceFileExists").Value = 1
  9.             End If
  10.         Next

Newbie
 
Join Date: Aug 2007
Location: PDX
Posts: 2
#2: Aug 3 '07

re: Finding files in a directory that begin with string


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

Quote:

Originally Posted by datamonk

...
If AllFiles(I).StartsWith("PDE") Then

Moderator
 
Join Date: Oct 2006
Location: Australia
Posts: 7,748
#3: Aug 4 '07

re: Finding files in a directory that begin with string


Quote:

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...
Expand|Select|Wrap|Line Numbers
  1. Dim AllFiles() As String = System.IO.Directory.GetFiles("\\fcfpsvr1\share\medicare\bipimport\incomingfiles\  ", "PDE*.txt")
Reply