Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 974
  • Last Modified:

SSIS 2008R2 VB.NET Script: How to get the file name from a full path

Hi All

I have a ForEach File Loop where I'm assigning the full path of a file to variable @sSourceFile.  Good to go.

Question:  Using either VB.NET script or a Derived Column expression, how do you get the file name?

Example:  @SourceFile = "H:\go\here\then\go\there\foo.txt"
Desired value:  foo.txt
0
Jim Horn
Asked:
Jim Horn
2 Solutions
 
Brian CroweDatabase AdministratorCommented:
SELECT SUBSTRING(@SourceFile, LEN(@SourceFile) - CHARINDEX('\', REVERSE(@SourceFile)) + 2, LEN(@SourceFile))
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
Figured it out.

Up top in the declarations section...
Imports System.IO

Open in new window

... then in the main ...
Dim fi As System.IO.FileInfo = New FileInfo(Dts.Variables("sSourceFile").Value.ToString)
MsgBox("File name " + fi.Name)

Open in new window


Lowered points and awarded for the T-SQL answer, which may have been used if I couldn't come up with a VB.NET answer.

Thanks.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now