Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-10-30
2
Medium Priority
?
968 Views
Last Modified: 2016-02-11
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
Comment
Question by:Jim Horn
2 Comments
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 1000 total points
ID: 39612672
SELECT SUBSTRING(@SourceFile, LEN(@SourceFile) - CHARINDEX('\', REVERSE(@SourceFile)) + 2, LEN(@SourceFile))
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 0 total points
ID: 39612697
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question